We recommend that you start a background thread button first. Isn't that okay? Then start a foreground thread. Check whether the front-end thread is tenacious and you are not finished! It will never be forgotten!
Using system; using system. drawing; using system. windows. forms; using system. threading; namespace windowsformsapplication1 {public partial class form1: FORM {public form1 () {initializecomponent ();} private void button1_click (Object sender, eventargs E) {// The only difference between the foreground thread and the background thread is that the application must run all foreground threads before exiting. // For background threads, the application can exit directly regardless of whether it has been run. // all background threads automatically end when the application exits. MessageBox. Show ("click to start a foreground thread. \ R \ n front-end thread: "since I came on stage, I must finish the performance, or I will not finish it with you !" "); // Foreground thread T1 = new thread (say); t1.isbackground = false; t1.name =" foreground thread "; t1.start ();} private void button2_click (Object sender, eventargs e) {MessageBox. show ("click the button to start a background thread. \ R \ n background thread: "Since I didn't come on stage, I am subject to the application. If it is off, I turn it off automatically (the stage is closed, I can't help working in the background )!" "); // Background thread t2 = new thread (say); t2.isbackground = true; t2.name =" background thread "; t2.start ();} private void say () {for (INT I = 0; I <100; I ++) {MessageBox. show ("I play, I play! \ N \ r closed the main window. Are you sure I am not there yet? "+ I. tostring ());}}}}
Friendly reminder: This is a winform program. What is stuck here is the content of the code window, and there is no content in the design field. So you have to create your own project to run the program, pull two buttons, enter the code window, and copy all the copies here to overwrite it and then you can press F5. To save time, the button name is default.