![](/img/trans.png)
[英]Multiple STA (Single Thread Apartment ) is not working in asp.net web application
[英].Net Core web application running STA thread
我想在 STA 模式下在控制器中运行 GET 方法。 对于 Web API,这非常有效: http : //ryanhaugh.com/archive/2014/05/24/supporting-sta-threads-in-web-api/可以转换为 .NET Core 吗?
我现在用同样的方式来做,除了我以不同的方式创建我的线程。
Example example = new Example();
Thread thread = = new Thread(
delegate () //Use a delegate here instead of a new ThreadStart
{
example.StaRequired(); //Whatever you want to call with STA
}
)
{
IsBackground = false,
Priority = ThreadPriority.Normal
};
thread.SetApartmentState(ApartmentState.STA);
thread.Start(); //Start the thread
thread.Join(); //Block the calling thread
IsBackground
和Priority
部分当然是可选的。
希望这有助于某人
要使用 STA,我创建了新线程:
ComClass c = new ComClass();
Thread t = new Thread(new ThreadStart(() =>
{
c.StaRequired();
}));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.