-1
我正在創建一個線程並讀取數據集並將記錄寫入excel。 但是,讀取25條記錄後,線程並未讀取完整記錄並在中間斷開。線程拋出HRESULT 800ac472錯誤
If dsCostUsage.Tables(0).Rows.Count > 150 Then
Dim t As New Thread(AddressOf FillDataRows1)
t.Start(worksheet)
End If
Private Sub FillDataRows1(ByVal ws As Worksheet)
Dim startuprow As Integer = 7
Dim colpointer As Integer = 0
Dim rowpointer As Integer = 0
Dim str As String
While rowpointer <= dsCostUsage.Tables(0).Rows.Count - 1
While colpointer <= dsCostUsage.Tables(0).Columns.Count - 1
str = dsCostUsage.Tables(0).Rows(rowpointer)(colpointer).ToString()
DirectCast(ws.Cells(startuprow, colpointer + 1), Range).Value2 = item
colpointer += 1
End While
colpointer = 0
rowpointer += 1
startuprow += 1
End While
End sub
不知道確切的原因,因爲它在中間休息。 無論如何,我們需要增加時間或其他方面嗎?
我認爲在工作線程完成寫入之前,主線程完成並中斷工作線程不繼續。