Multithreading |
//Control.CheckForIllegalCrossThreadCalls = false; //Examples of thread-safe cross-threaded calls in C# private delegate void SetTextCallback(string text); private delegate void GetTextCallback(Control control); string controlText = ""; private void setStatusBarText(string text) { if (this.statusBar.InvokeRequired) { SetTextCallback d = new SetTextCallback(setStatusBarText); this.Invoke(d, new object[] { text }); } else { statusBarPanel2.Text = text; } } private void getControlText(Control control) { if (control.InvokeRequired) { GetTextCallback d = new GetTextCallback(getControlText); control.Invoke(d, new object[] { control }); } else { controlText = control.Text; //MessageBox.Show("Control text = " + controlText); } } |
using System.Threading; private void plot_butn_Click(object sender, System.EventArgs e) { if (statusBarPanel2.Text == "Plotting...") { interruptPlotMessage(); return; } //Function_Plot(); stop_plot = false; Thread thrPlotting = new Thread(new ThreadStart (Function_Plot)); thrPlotting.IsBackground = true; thrPlotting.Priority = ThreadPriority.AboveNormal; thrPlotting.Start(); } |