워크 북에 다양한 데이터를 출력하는 데 사용되는 ExcelOutput
클래스가 포함 된 BackgroundWorker
이 있으며 바로 bw.WorkerSupportsCancellation = True
이 설정되어 있음을 언급해야합니다.BackgroundWorker procss를 취소 할 수 없습니다
Try/Catch
를 사용
ExcelOutput
의 오류를 검사하고있어, 출력의 각 단계에서
및 ErroReport()
라는 함수를 사용하여 (에러 표시 필요한 경우. 오류 메시지와 함께
는, I는 취소 할 BackgroundWorker
는이를 위해 내가 추가했습니다. ExcelOutput
클래스에 OutputWorker
속성을 추가 오류를 방지하고 나는이 bw_DoWork()
방법에 내 BackgroundWorker
의 카피로 설정합니다.
그러나 ExcelOutput.ErroReport()
에서 수행 취소가 가공용 아니다 응, 왜 그런지 모르겠다.
나는 bw.CancellationPending
의 값을 테스트했으며 오류 발생 후 True
으로 설정되었습니다. 또한 메시지 상자를 표시하여 If
조건이 작동하는지 테스트 한 결과 작동합니다. 웬일인지 Exit Sub
명령이 무시되는 것처럼 보인다.
누구든지 내가 뭘 잘못하고 있다고 제안 할 수 있습니까? 감사.
Private Sub ErrorReport(ByVal Ex As Exception,
Optional ByVal CustomMessage As String = "")
Call Me.ResetRange() ' Destroy the 'Range' object
Dim ErrorMessage As String = "Message: " & Ex.Message ' Set the default message
If CustomMessage <> "" Then ErrorMessage = CustomMessage & vbCrLf & vbCrLf & Ex.Message
Dim Result As Integer = MessageBox.Show(ErrorMessage,
"An Error Has Occured",
MessageBoxButtons.OK,
MessageBoxIcon.Stop)
'** Close the workbook (if it's open) and stop the OutputWorker *'
Try
Call Me.WB.Close(SaveChanges:=False)
If Me.OutputWorker.WorkerSupportsCancellation = True Then
Me.OutputWorker.CancelAsync()
End If
Catch
End Try
End Sub
고마워.하지만 같은 결과가 나왔어. –