WinForm Video Tutorial-task timed Loop execution widget

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.