是否可以打开将在不同线程上运行的表单?

编程入门 行业动态 更新时间:2024-10-21 10:00:57
本文介绍了是否可以打开将在不同线程上运行的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

是否可以打开将在不同线程上运行的表单?

本文发布于:2023-11-12 12:24:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581490.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将在   表单   线程

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!