Thread thNetwork;
thNetwork = new Thread(new ThreadStart(GetNetworkInfo));//创建一个线程
thNetwork.Start();//执行当前线程

public void GetNetworkInfo()
{
    //函数的代码
}

其中GetNetworkInfo是新线程的函数。
在GetNetworkInfo里执行代码的时候,我们有时候需要修改主线程里的东西,可以利用另外一个函数来实现。

this.Invoke(new MethodInvoker(SetAuthorDisplay));

这里的SetAuthorDisplay是主线程的函数

或者是用以下的方式:

this.Invoke(new MethodInvoker(delegate {/*这里是需要访问主线程的代码*/}));

 

相关文章: