Web Development

General discussion


VB keeps giving ContextSwitchDeadlock

By Frenchwood ·
I have a VB program that uploads to Oracle via a CSV file. This all works great, apart from the MDA in Visual Basic 2005 Express keeps telling me the following:

"ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x1a3008 to COM context 0x1a3178 for 60 seconds. 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."

Any ideas?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by Frenchwood In reply to VB keeps giving ContextSw ...

I have resolved this, after much reading into STA threading...

For information, the resolution i used for this is:

Imports System
Imports System.Threading

Sub Main()
Dim t as New Thread(AddressOf ThreadProc)


End Sub

This sets the app to Multiple Threading and resolves the issue.

I still have an issue with the windows form "White Screening" and comes back as Not Responding, but this may (or may not) due to the amount of COM calls made to the oracle DB. Any comments anyone?

Collapse -

Process events...

by tero.ronkko In reply to


You can avoid whitescreening and MDA deadlock by calling Application.DoEvents(); function every now and then in your loop. I am in middle of similar task as you and (transferring and translating data from one oracle table in one database to another in another database and this takes longer than 60s) I found your article.

DoEvents() processes windows messages and causes the application to still be responsive to user clicks/things. You don't even have to call it every iteration, every 100th or so is quite enough.


Collapse -

same problem

by ileana_eugenia In reply to

I have the same problem with the this thread but in my case ThreadProc in a function and I have the error:

Overload resolution failed because no accessible 'New' can be called with these arguments: 'Public Sub New(start As System.Threading.ParameterizedThreadStart)': Method 'Private Sub conv_str(str As String, provider As String)' does not have the same signature as delegate 'Delegate Sub ParameterizedThreadStart(obj As Object)'.
'Public Sub New(start As System.Threading.ThreadStart)': Method 'Private Sub conv_str(str As String, provider As String)' does not have the same signature as delegate 'Delegate Sub ThreadStart()'.

please some ideea.

Collapse -

by RRV In reply to VB keeps giving ContextSw ...

In the form load event put the below line. If the word is not exactly correct, Intellisense will help you.

Control.CheckforIllegalCrossThreadCalls = False

This will avoid your problem.

Good luck

Related Discussions

Related Forums