How can I multithread (effectively) on Windows Forms?

This seems to work... using System; using System.Collections. Generic; using System. ComponentModel; using System.

Data; using System. Drawing; using System. Linq; using System.

Text; using System.Windows. Forms; using System. Threading; namespace WindowsFormsApplication2 { public partial class Form1 : Form { private BackgroundWorker _bw = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true}; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (_bw.

IsBusy) { _bw.CancelAsync(); } else { _bw. ProgressChanged += new ProgressChangedEventHandler(_bw_ProgressChanged); _bw. DoWork += new DoWorkEventHandler(_bw_DoWork); _bw.RunWorkerAsync(); } } void _bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { textBox1.

Text += (string)e. UserState; } void _bw_DoWork(object sender, DoWorkEventArgs e) { int count = 0; while (!_bw. CancellationPending) { _bw.

ReportProgress(0, string. Format("worker working {0}", count)); ++count; Thread. Sleep(2000); } } } }.

Worked! Yes, as Ani said I was setting the CancellationPending property to true, but I wasn't actually cancelling. The curious thing is that in the console it actually worked.

Thanks! – chatran20 Jan 24 at 19:42 can you mark the question answered? Thanks!

– Marco Jan 26 at 6:34 I guess not :P – anon271334 Mar 18 at 17:26.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions