检测到DisconectedContext [英] DisconectedContext was detected

查看:107
本文介绍了检测到DisconectedContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要摆脱此错误的帮助:

I need help getting rid of this error:

为此RuntimeCallableWrapper转换为COM上下文0x465608 失败,出现以下错误:系统调用失败. (来自的例外 HRESULT:0x80010100(RPC_E_SYS_CALL_FAILED))通常是 因为该RuntimeCallableWrapper所在的COM上下文为0x465608 创建的对象已断开连接,或者正忙于执行其他操作. 从当前COM上下文(COM上下文)释放接口 0x465498).这可能会导致损坏或数据丢失.为了避免这种情况 问题,请确保保留所有COM上下文/公寓/线程 并可以进行上下文转换,直到应用程序 完全由代表的RuntimeCallableWrappers完成 驻留在其中的COM组件."

"Transition into COM context 0x465608 for this RuntimeCallableWrapper failed with the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)). This is typically because the COM context 0x465608 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else. Releasing the interfaces from the current COM context (COM context 0x465498). This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them."

在执行此代码期间发生的情况:

Which occurs during the execution of this code:

int i = 2;

while(i <= lastRowPOPT)
{
     RefDocNo = poptSheet.Cells[i, 1].Text;
     RefItem = poptSheet.Cells[i, 2].Text;
     Plnt = poptSheet.Cells[i, 3].Text;
     concat = RefDocNo + RefItem + Plnt;
     poptSheet.Cells[i, 8] = concat;
     poptSheet.Range["E" + i, "G" + i].Copy(Type.Missing);
     poptSheet.Range["I" + i, "K" + i].PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteAll);

     i++;
}

大约有4700行,它在1000左右上完成工作,然后抛出该行.执行过程大约持续4分钟,但我认为大部分时间都会停顿.

There are around 4700 rows and it does it's job on 1000 and something, then it throws that. Also the execution lasts about 4 mins, but I think it stalls most of that time.

推荐答案

由于我没有找到任何解决方案,因此我使用了OleDbConnection和DataSet代替了Interop服务,因此一切工作正常.

Since I didn't find any resolution for that, I used an OleDbConnection and a DataSet instead of Interop services so everything works fine like that.

这篇关于检测到DisconectedContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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