Simple example of the usage of BackgroundWorker control in WinForm
This article describes the usage of BackgroundWorker control in WinForm. Share it for your reference. The details are as follows:
using System; using ; using ; using ; using ; using ; using ; using ; namespace WinFormApp { public partial class Form2 : Form { BackgroundWorker backgroundWorker; int i = 0; int len = 100; public Form2() { InitializeComponent(); backgroundWorker = new BackgroundWorker(); += new DoWorkEventHandler(backgroundWorker_DoWork); += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted); += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); = true; } void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { (label2, "schedule:" + ()); // = ; } void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { (label3, "Result: completed"); } void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { (label3, "Result:start"); while (i < len) { i++; (100); (label1, "Work:" + (i * 10).ToString()); (i); (); } } private void button1_Click(object sender, EventArgs e) { (); } } }
I hope this article will be helpful to everyone's C# programming.
Related Articles
Unity shader implements Gaussian blur effect
This article mainly introduces in detail to Unity shader to realize Gaussian blur effect, which has certain reference value. Interested friends can refer to it.2019-02-02Detailed explanation of Thread (thread) and Task (task) instances in C#
.NET Framework has thread-related classes in the namespace. Threads are a small group of executable instructions. This article mainly introduces relevant information about Thread (thread) and Task (task) in C#. Friends who need it can refer to it.2022-03-03Detailed explanation of how to implement UI control output logs in C#
Generally speaking, our log files are used to record some key operations or exceptions, and are stored in the background and are not open to the public. However, sometimes, some operation steps, records, etc. need to be displayed directly on the form. This article will use UI controls to output log effects. If you need it, please refer to it.2022-10-10C# uses generic queue Queue to implement production and consumption mode
This article introduces C#'s method of using generic queue Queue to implement production consumption patterns. The article introduces it in detail through sample code. It has certain reference value for everyone's study or work. Friends who need it can refer to it.2022-10-10Analysis of the difference between and in C#
This article shows us the difference between _ and _ in C# through example code. The article is easy to understand and is recommended to you here.2014-11-11C# depth priority traversal achieves full permutation
This article mainly introduces the full arrangement of C# depth priority traversal. The example code is introduced in this article in detail, which has certain reference learning value for everyone's learning or work. Friends who need it, please learn with the editor below.2019-11-11Unity Shader achieves glass material effect
This article mainly introduces the effect of Unity Shader in detail to achieve glass material. The sample code in the article is introduced in detail and has certain reference value. Interested friends can refer to it.2020-04-04C# multi-threaded asynchronous execution and cross-thread access control Helper
This article introduces C# multi-threaded asynchronous execution and cross-thread access control Helper. The article introduces the example code in detail. It has certain reference value for everyone's study or work. Friends who need it can refer to it.2022-04-04Sample code for visualization based on ScottPlot
This article mainly introduces in detail how C# can achieve visualization effects based on ScottPlot. The sample code in the article is explained in detail and has certain reference value. Interested friends can follow the editor to learn it.2024-01-01Detailed explanation of the principle of ValueTuple in C#
C# 7.0 has been out for a while, and everyone knows that there is an optimization of tuples in the new feature: ValueTuple. The following article mainly introduces relevant information about the principle of ValueTuple in C#. Friends who need it can refer to it. Let’s learn and learn together with the editor.2018-06-06