Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Safe update of windows control from other threads (See related posts)

        delegate void UpdateReportCallback(string text);
        private void UpdateReport(string message)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.textBoxReport.InvokeRequired)
            {
                UpdateReportCallback d = new UpdateReportCallback(UpdateReport);
                this.Invoke(d, new object[] { message });
            }
            else
            {
                textBoxReport.Text = message + System.Environment.NewLine + textBoxReport.Text;
            }
        }

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts