任何人都可以告诉我是否有可能有一个主窗体包含按钮打开一个将在单独的线程上运行的窗体?我试过这样做并得到以下错误: 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.
更多推荐
是否可以打开将在不同线程上运行的表单?
发布评论