multithreading - Invoke Windows Form Thread and Sleeping -


I have a managed C ++ application that I start a new thread to do some stuff and some text boxes I update, it loops and sleeps at the end of each loop, because of this sleep I need to keep it in a new thread so that the UI does not crash. Then I realized that I needed to use the thread which made the UI to reach the text boxes, but now I'm back in the main thread so that there is a crash in sleep. How should i contact this

  Private: System :: Zero Button StartCamergalic (System :: Object Sender, System :: EventArgs ^ e) {Thread Start ^ thread Start = GCNU ThreadStart (This, & UserInterface :: setText ); Thread ^ newThread = gcnew thread (threadstart); NewThread- & gt; Start (); } Zero set-test () (if-> this-> Text box cameraAnx-> Invovaruair) {MyDel ^ del = gcnew MyDel (This, and User Interface :: Settext); This- & gt; Invoke (Dell) ;} And {int count = 0; Srand (time); (calculation = 0; count & lt; 20; ++ calculation) {For each camera in camera = Count.ToString ();} Sleep (300);}}}    

The best option is the possibility to do this again so that you do not sleep, your page is within the Settext method The thighland thread can use a different method that demonstrates sleep, and then calls the appropriate method to set the text in a loop.

In general, They should only include the necessary logic for your UI work, and other functionality -

It is being said, In this case, it seems that sis System :: Windows :: Forms :: Timer would be more appropriate. You can set the interval in 300 , and you can update the text box in the timer's tick event at a time.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -