Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

.net - thread is throwing HRESULT 800ac472 error

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could try calling t.Join()

That should make the main thread wait until the other(s) finish.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...