本文介绍了是否可以打开将在不同线程上运行的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何人都可以告诉我是否有可能有一个主窗体包含按钮打开一个将在单独的线程上运行的窗体?我试过这样做并得到以下错误:

System.Threading.ThreadStateException未处理





































线程不在单线程单元中。"
Source =" System.Windows.Forms"

StackTrace:
在System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
在System.Windows.Forms.WebBrowser..ctor()
中的AdPosters.Form2.InitializeComponent()在C:\ Project:\\ AdPosters \ AdPosters \Dialers\Form2.Designer.cs:第32行
在AdPosters.Form2..ctor()中的C:\Projects \AdPosters \AdPosters \Dialers\Form2.cs:第18行
位于AdPosters.Form7.ThreadProc()的C:\\ \\ ProjectPh:System.Threading.Thread.ThreadStart_Context(Object state)
System.Threading.ThreadHelper.ThreadStart()中的eading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)


如果是,请提供一些样本吗? >
提前谢谢,
Joe

Hi,

Can anyone please tell me if it's possible to have a main form that includes button which opens a form which will run on a seperate thread? I have tried doing it and got the following error:

System.Threading.ThreadStateException was unhandled
  Message="ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."
  Source="System.Windows.Forms"
  StackTrace:
       at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
       at System.Windows.Forms.WebBrowser..ctor()
       at AdPosters.Form2.InitializeComponent() in C:\Projects\AdPosters\AdPosters\Dialers\Form2.Designer.cs:line 32
       at AdPosters.Form2..ctor() in C:\Projects\AdPosters\AdPosters\Dialers\Form2.cs:line 18
       at AdPosters.Form7.ThreadProc() in C:\Projects\AdPosters\AdPosters\Form7.cs:line 677
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


If it is, can you please provide some samples?

Thanks in advance,
Joe

推荐答案

使用旧版ActiveX的表单,否。您将拥有在第二个线程之外创建ActiveX的实例,并可能将其传递给重载的表单构造函数以接受activeX对象,然后才能在另一个线程中使用该表单。

Form with legacy ActiveX, No. You will have to create an instance of the ActiveX outside the second thread, and probably pass it to the form constructor overloaded to accept an activeX object before you can use the form in another thread.


这篇关于是否可以打开将在不同线程上运行的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 18:18