Wrote a program to filter large text, in which the method inside uses multi-threading, parallel threads and other methods. However, when the main form control uses this method directly, the page is stuck. So the main thread is blocked. The code below, Splitfile this method runs when the page is stuck, blocking the main thread
Private voidButton3_Click (Objectsender, EventArgs e) {marqueeprogressbarcontrol1.visible=true; MarqueeProgressBarControl1.Properties.ShowTitle=true; Marqueeprogressbarcontrol1.text="Data Processing ... Please, later ..."; stringFile =TxtPath.Text.Trim (); Spiltfile (file,1); Marqueeprogressbarcontrol1.visible=false; }
Change to this:
true ; true ; " Data Processing ... Please, later ... " ; New Thread (new ThreadStart (Run)); Thread. Start ();
Involves accessing controls inside a method, so use the invoke that is left specifically for the UI main thread
this. Invoke (new EventHandler (delegate { thisfalse; }));
C # Run the Big OP program main form card out of the solution