Sometimes, we may encounter such a requirement, that is, we need to have a small tool, constantly perform some tasks in the server, then we can do a Windows service program, or do a WinForm WPF and other small programs, and then open a thread in the applet, Code is constantly executing in the thread
Then the nonsense will not say more, first see www.it404.cn
The program is simple, but the basic function of continuous cycle scanning has been
First, in Formload, we open a sub-thread.
Private void Formmain_load (object sender, EventArgs e) { /// window is loaded when a child thread is opened New Thread (new Parameterizedthreadstart (Run)); Thread. Start (); }
Then create a delegate method run
Private void Run (object obj) { // write here the code for our child thread while (True ) { thread.sleep (+); Let the current thread here is the child thread this " >> \ r \ n"this . richTextBox1.Text; } }
The delegate method return value must be void and have only one object argument
Then you also want to cancel the cross-thread exception
Public FormMain () { InitializeComponent (); false ; // after setting the Checkforillegalcrossthreadcalls to False, our control will not be able to report the exception of the thread access. }
North Alliance Network www.bamn.cn
OK, the code is simple, but it is estimated that many projects or many places to use, thank you for reading ....
Video download: Http://pan.baidu.com/s/1dDHCkId/Winform Video Tutorial-Task timing execution tool. wmv
WinForm Video Tutorial-task timed Loop execution widget