I am creting a thread and reading the dataset and writing the records into excel.
But the thread is not reading complete records and breaks in the middle after reading 25 records.
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
Dont know the exact reason whhy it breaks in the middle.
Is there anyway that we need to increase the time or anhything else is there?
I think before worker thread completes writing, the main thread completes and interrupt the worker thread to not to continue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…