是在此示例中在主线程上执行的Windows.Forms.Form上调用的操作?

时间:2012-09-16 22:06:51

标签: c# multithreading

我正在尝试用C#编写服务器,并且在线程委派和通信方面存在一个基本问题。

    using System.Windows.Forms;

// main thread..
callbackform = new Form();
callbackform.createControl();
int dummy = callbackform.Handle.ToInt32();

// here I create a new thread to connect to a server and handle messages from server

// main thread loops indefinitely
Application.run(new ApplicationContext());

现在,Form实现了ISynchronizeInvoke接口。因此,如果我想在主STA上同步或异步执行方法 线程,我可以使用callbackform.InvokeRequired / BeginInvoke / EndInvoke / Invoke(...)函数吗?

Form / Control / Handle对象是否创建新线程,在这种情况下,他们管理的线程与主线程不同,我委托给Form的操作实际上不会在主STA线程上执行?

这是正确的理解还是我错过了一些基本的东西?我开始使用C#编写非GUI服务器。

0 个答案:

没有答案