2014-03-24 2 views
1
이 오류를 제거하는 데 도움이 필요

:DisconectedContext가 감지되었습니다

이 코드의 실행 중에 발생

"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."

:

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 분 동안 지속되지만, 나는 그 시간의 대부분을 멈추게한다고 생각한다.

답변

0

나는 그 해결책을 찾지 못했기 때문에 Interop 서비스 대신 OleDbConnection과 DataSet을 사용 했으므로 모든 것이 잘 작동합니다.

0

알아 냈습니다. 외관상으로, 외부 프로세스 (이 경우 Excel)가 너무 오래 실행될 때 운영 체제는 다른 응용 프로그램을 실행하지 못하게한다고 생각합니다. 진단은 무서웠지만 해결책은 매우 간단합니다. 다른 프로세스가 실행될 수 있도록 다음 코드 줄을 하나 이상의 위치에 추가하면 문제없이 긴 실행이 완료됩니다.

System.Windows.Forms.Application.DoEvents() 
+0

이 해결책은 일반적으로 보이지 않습니다. 해결하려고 시도한 상황에 대해 더 구체적으로 설명해주십시오. –

관련 문제