T
tc
I have a routine that need to process individual records in data tables,
change values, and add other records to other tables for history purposes.
This may be one or two records, it could be several thousand depending upon
what the user has selected in a grid.
On a long run (large loop) I get the following error on the development
machine:
The thread that owns the destination context/apartment is most likely either
doing a non pumping wait or processing a very long running operation without
pumping Windows messages. This situation generally has a negative
performance impact and may even lead to the application becoming non
responsive or memory usage accumulating continually over time. To avoid this
problem, all single threaded apartment (STA) threads should use pumping wait
primitives (such as CoWaitForMultipleHandles) and routinely pump messages
during long running operations.
My SQL code is a simple sub:
If DBType = "MSSQL" Then
Dim con As New SqlConnection(MsSqlConnString)
con.Open()
Try
Dim tr As SqlTransaction =
con.BeginTransaction(IsolationLevel.ReadCommitted)
Dim com As New SqlCommand(sql, con, tr)
com.ExecuteNonQuery()
tr.Commit()
com = Nothing
tr = Nothing
If Left(LCase(sql), 6) = "insert" Then
Dim lid As New SqlCommand("SELECT @@IDENTITY", con)
LastID = CLng(lid.ExecuteScalar)
lid.Dispose()
End If
Catch ex As Exception
con.Close()
MsgBox(ex.ToString & vbCrLf & vbCrLf & sql)
End Try
con.Close()
con.Dispose()
End If
There is obviously something happening here that shouldn't, can anyone
explain why the threads are getting messed up with such simple code? And
how to setup pumping?
Thanks,
TC.
change values, and add other records to other tables for history purposes.
This may be one or two records, it could be several thousand depending upon
what the user has selected in a grid.
On a long run (large loop) I get the following error on the development
machine:
The thread that owns the destination context/apartment is most likely either
doing a non pumping wait or processing a very long running operation without
pumping Windows messages. This situation generally has a negative
performance impact and may even lead to the application becoming non
responsive or memory usage accumulating continually over time. To avoid this
problem, all single threaded apartment (STA) threads should use pumping wait
primitives (such as CoWaitForMultipleHandles) and routinely pump messages
during long running operations.
My SQL code is a simple sub:
If DBType = "MSSQL" Then
Dim con As New SqlConnection(MsSqlConnString)
con.Open()
Try
Dim tr As SqlTransaction =
con.BeginTransaction(IsolationLevel.ReadCommitted)
Dim com As New SqlCommand(sql, con, tr)
com.ExecuteNonQuery()
tr.Commit()
com = Nothing
tr = Nothing
If Left(LCase(sql), 6) = "insert" Then
Dim lid As New SqlCommand("SELECT @@IDENTITY", con)
LastID = CLng(lid.ExecuteScalar)
lid.Dispose()
End If
Catch ex As Exception
con.Close()
MsgBox(ex.ToString & vbCrLf & vbCrLf & sql)
End Try
con.Close()
con.Dispose()
End If
There is obviously something happening here that shouldn't, can anyone
explain why the threads are getting messed up with such simple code? And
how to setup pumping?
Thanks,
TC.