**************异常文本************** System.AccessViolationException : 尝试读取或写入受保护的内存。这通常表明其他内存已损坏。 at MSFlexGridLib.IMSFlexGrid.get_Text() at AxMSFlexGridLib.AxMSFlexGrid.get_Text() 在System.Windows.Forms.Control.OnHandleDestroyed(Eve ntArgs e) 在System.Windows.Forms.AxHost.DetachWindow() 在System.Windows.Forms .AxHost.DetachAndForward(Messa ge& m) 在System.Windows.Forms.AxHost.WndProc(消息& m) 在System.Windows.Forms.Control。 ControlNativeWindow.O nMessage(Message& m) 在System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m) 在System.Windows.Forms。 NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 7. COde片段如下所示。 HI Friends, I am facing a problem while joining a STA thread to MTA thread. Actually the requirement was some thing like describe below.1. I have a exe which is using some dialog boxes. 2. These dialog boxes are using MSFlexGrid. This component is a Com component. 3.so in order to run it with Vb.Net exe i had to run this dialog box in a STA thread. 4. to achive this i created a new thread and set the Apartment status STA.5.it was working fine when i run the code. but if click on exe than at the time of join it throws an unhandled exception.if i click on continue button of exception dialog box it runs successfully. how ever i can not ignore this exception.6. exception contains below text (i know its a bog message but i am stuck here for last couple of days.). ************** Exception Text **************System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at MSFlexGridLib.IMSFlexGrid.get_Text() at AxMSFlexGridLib.AxMSFlexGrid.get_Text() at System.Windows.Forms.Control.OnHandleDestroyed(Eve ntArgs e) at System.Windows.Forms.AxHost.DetachWindow() at System.Windows.Forms.AxHost.DetachAndForward(Messa ge& m) at System.Windows.Forms.AxHost.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 7. COde snippet is like below. 展开 | 选择 | Wrap | 行号 推荐答案 你能让你的整个项目成为STA吗? 或者更确切地说,创建一个调用并启动该线程的辅助线程第三个帖子? 另外,你为什么使用msflexgrid?您是否了解DataGridView?Can you make your whole project STA?Or rather make a secondary thread that calls and starts that thread as a third thread? Also, why are you using msflexgrid? Are you aware of DataGridView? 实际上它是一个非常大的Vb6.0到VB.Net的迁移项目。它包含大约16个组件。我无法将整个项目作为STA。 我知道DataGridView,但现在它无法更改组件,因为它在许多其他应用程序中使用。我遇到了msflexgrid的问题。所以我创建了一个线程并将公寓设置为STA。最初它工作正常(或可能是我忽略了错误)。但现在它给了我上面提到的错误。我只是想知道是否有任何指南加入STA与MTA。我也试过了事件机制,但似乎这个线程死了就会出现这个错误。Actually its a very large Vb6.0 to VB.Net migrated project. it contains some 16 components. i can not make whole project as STA.i know about DataGridView but right now its not possible to change the component, as its being used in many other applications. I had a problem with msflexgrid. so i created a thread and set the apartment as STA. initially it was working fine(or may be i ignored the error). but now it gives me the above mentioned error. i just wanted to know if there is any guideline to join a STA with MTA. i have tried event mechanism also, but it seems like when this thread dies it gives this error. 为什么在Start()之后调用Join()? 编辑:没关系,我猜想。 如果你制作了自己的Join()版本怎么办? 像循环这样的东西当那个线程仍处于活动状态时。 在你的循环中你会打电话给 Application.DoEvents 和 Thread.Sleep(100) 如果你不想让它永远等待,也许可以检查一个DateTime对象Why do you call a Join() right after the Start()? Nevermind that I suppose. What if you made your own version of Join()?Something like looping while that thread is still active.And in your loop you would call Application.DoEvents and Thread.Sleep(100) And maybe checking a DateTime object if you don''t want it to wait forever 这篇关于将STA线程加入MTA线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 02:13