Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

report background worker

public partial class Form1 : Form
{
    private BackgroundWorker backgroundWorker1;
    private testClass t1 = new testClass();

    public Form1()
    {
        InitializeComponent();

        // subscribe to your event
        t1.OnProgressUpdate += t1_OnProgressUpdate;
    }

    private void t1_OnProgressUpdate(int value)
    {
        // Its another thread so invoke back to UI thread
        base.Invoke((Action)delegate
        {
            label1.Text += Convert.ToString(value);
        });
    }

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        t1.changevalue(1000);
    }

    private void button1_Click_1(object sender, EventArgs e)
    {
        backgroundWorker1.RunWorkerAsync();
    }

}

class testClass
{
    public delegate void ProgressUpdate(int value);
    public event ProgressUpdate OnProgressUpdate;

    private int val;
    public int changevalue(int i)
    {
        for (int j = 0; j < 1000; j++)
        {
            val += i + j;

            // Fire the event
            if (OnProgressUpdate != null)
            {
                OnProgressUpdate(i);
            }
        }
        return val;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: netlifycms disable preview 
Csharp :: add integer to string c# 
Csharp :: nunit return parameter 
Csharp :: visual studio import excel get document created date 
Csharp :: .NET TLS 1.3 example 
Csharp :: c# validate username and password 
Csharp :: how to select multiple toggles at once in unity 
Csharp :: c# dubble comment 
Csharp :: c# lernen kostenlos 
Csharp :: Acrylic UWP Title bar C# 
Csharp :: FileSystemEventHandler raised twice 
Csharp :: c# null coalescing operator 
Csharp :: rigidbody velocity 
Csharp :: c# datagridview count value 
Csharp :: qrcode c# 
Csharp :: Insertion sort in c# 
Csharp :: c# if int is even 
Csharp :: c# get pixel from bitmap click 
Csharp :: Task w = Task.Delay(600);w.Wait();new Program().Start(); 
Csharp :: make winform open first 
Csharp :: RadioButton IsChecked mapped to ENum xmal 
Html :: open page with html 
Html :: how to open link in a new tab 
Html :: fontawesome phone icon 
Html :: html entity quote 
Html :: bootstrap col-md-5 center 
Html :: html5 embed pdf base64 
Html :: html hide a div by default 
Html :: js onclick redirect 
Html :: jinja2 iterate dict 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =