In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the example analysis of the control operation problem of C# subthread". In the daily operation, I believe that many people have doubts about the control operation problem of C# subthread. The editor consulted all kinds of data and sorted out the simple and useful operation method. I hope it will be helpful for you to answer the doubt of "example analysis of control operation problem of C# subthread". Next, please follow the editor to study!
Control operations related to C # child threads
Generally speaking, the operation of the control on the form directly in the child thread will cause an exception, because the child thread and the thread running the form are in different space, so if you want to operate the control on the form in the child thread, it is impossible to operate through the control object name, but it does not mean that the operation cannot be carried out. Microsoft provides the method of Invoke. Its function is to let the child thread tell the form thread to complete the corresponding control operation.
Now use a thread-controlled process bar to illustrate, the general steps are as follows:
1. Create the Invoke function, roughly as follows:
/ / /
< summary>/ Delegate function to be invoked by main thread /
< /summary>Private void InvokeFun () {if (prgBar.Value
< 100 ) prgBar.Value = prgBar.Value + 1; } 2. C#子线程入口函数: /// < summary>/ Thread function interface /
< /summary>Private void ThreadFun () {/ / Create invoke method by specific function MethodInvoker mi = new MethodInvoker (this.InvokeFun); for (int I = 0; I < 100; iTunes +) {this.BeginInvoke (mi); Thread.Sleep (100);}}
3. Create a C# child thread:
Thread thdProcess = new Thread (new ThreadStart (ThreadFun)); thdProcess.Start ()
Note:
Using System.Threading; private System.Windows.Forms.ProgressBar prgBar; at this point, on the "C # child thread control operation example analysis" study is over, I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.