CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Control Refresh

Threaded View

  1. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Control Refresh

    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;
            }
        }
    Last edited by BigEd781; May 11th, 2009 at 02:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured