VS关闭时,COM对象与基础RCW错误分离 [英] COM object separated from underlying RCW error on VS close

查看:70
本文介绍了VS关闭时,COM对象与基础RCW错误分离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在.Net Framework 2.0.50727 SP 1上使用Visual Studio 8.0.50727.867 SP1开发C#加载项.对于大型文件(9000行,100多个函数,400KB +),它最接近cpp文件中的当前光标位置,这可能需要一秒钟左右的时间,并且在与外接程序的对话框进行交互时可能会导致混乱.

要解决此问题,我将函数放入一个单独的线程中,除非在运行该函数时关闭Visual Studio,否则该函数似乎可以正常工作,然后我得到一个无法使用与其基础RCW分离的COM对象".下一行的消息

sstudents(),(),还是因为,该线程正在尝试访问不再存在的内容.任何想法如何解决此问题?

在此先感谢.

CB

I'm developing an add-in with C# using Visual Studio 8.0.50727.867 SP1 on .Net Framework 2.0.50727 SP 1.

I have a function which identifies the code element (function) containing or nearest to the current cursor position within a cpp file, for big files (9000 lines, 100+ functions, 400KB+) this can take a second or so and can lead to the jerkiness when interacting with the add-in's dialog box.

To work around this I put the function into a separate thread which seems to work unless Visual Studio is closed while the function is running, then I get a "COM object that has been separated from its underlying RCW cannot be used." message on the following line

   TextPoint textPoint = ((TextSelection)doc.Selection).ActivePoint;

I assume this is happening because the thread is trying to access something that no longer exists. Any ideas how to fix this?

Many thanks in advance.

CB

推荐答案

关闭Visual Studio时您应该使用 Thread 向线程发送终止信号.中止方法:
ThreadAbortException类(System.Threading)

您可以订阅 DTEEvents.OnBeginShutdown事件,以了解VS何时开始关闭.
When Visual Studio is closed you should send the thread a terminate signal using Thread.Abort method:
ThreadAbortException Class (System.Threading)

You can subscribe to DTEEvents.OnBeginShutdown event to know when the VS start to shutdown.MZ-Tools Articles Series: HOWTO: Add an event handler from a Visual Studio add-in

Thanks.


这篇关于VS关闭时,COM对象与基础RCW错误分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆