1

我正在尝试用 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 服务器。

4

0 回答 0