You could, but that can lead to problems with re-entrancy and there are few situations using .NET where DoEvents is a necessary approach. You can do your processing in a BackgroundWorker and notify the UI in its DoWork event.
Code:public partial class Form1 : Form { public Form1( ) { InitializeComponent( ); } private void button1_Click( object sender, EventArgs e ) { BackgroundWorker worker = new BackgroundWorker( ); worker.DoWork += worker_DoWork; worker.RunWorkerAsync( ); } void worker_DoWork( object sender, DoWorkEventArgs e ) { for ( int i = 0 ; i < 1000000000 ; ++i ) { this.Invoke( new FooDelegate( Foo ), new object[ ] { i.ToString( ) } ); } } private delegate void FooDelegate( string text ); private void Foo( string text ) { label1.Text = text; } }




Reply With Quote