Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Drawing;
Using System.Linq;
Using System.Windows.Forms;
Using System.Threading;
Namespace Doworker
{
public partial class Form1:form
{
delegate void MyDelegate (int value);
Thread T;
int i = 0;
Public Form1 ()
{
InitializeComponent ();
}
Do a "long time" job in a new thread
private void Button1_Click (object sender, EventArgs e)
{
t = new Thread (doWork);
T.start ();
}
Work to be done for a long time
void DoWork ()
{
MyDelegate d = new MyDelegate (setValue);
while (true)
{
++i;
---winform--
This. Invoke (d, I);
----WPF---added by wonsoft.cn---
This. Dispatcher.invoke (d, I);
Thread.Sleep (100);
}
}
Update user interface
void SetValue (int value)
{
Label1. Text = value. ToString ();
}
Terminating the execution of a thread
private void Button2_Click (object sender, EventArgs e)
{
T.abort ();
}
}
}
WPF, WinForm (C #) multithreaded Programming and update interface (UI) (reproduced accumulation)