How do avoid time out expired in my VB 2008 aplication

Posted on 2011-03-23
Medium Priority
Last Modified: 2012-06-27
I have a form where I call a lot of  stored procedures in a MySQL database. In the procedures are same queries which execute updates, insert into etc.

Sometimes, during debugging, depending on the size of tables included in the queries, the program stops and appears the message below:

"The CLR has been unable to transition from COM context 0x1b0f58 to COM
context 0x1b10c8 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."

In the site there is a solution in C#, but I would like a solution for VB2008.

I Would like to Know if it is possible a solution by creating a new thread.


Question by:JGonzaga
  • 4
  • 3
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35198466
Yes...threading should solve your issue.  The easiest solution is to use the BackgroundWorker() and place your lengthy DB calls in the DoWork() handler.  If you need to update the GUI then use the ProgressChanged() and/or RunWorkerCompleted() events:

Author Comment

ID: 35199002
I´ve tried the solution with backgroundworker, but in the code there is a problem, because the varable BackgroundWorker, in the statement below, are not be recognized.

 Dim CalcEstq As BackgroundWorker = CType(sender, BackgroundWorker)

 In my code I´ve repleced Worker by CalcEstq
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35199179
The VARIABLE "CalcEstq" is not being recognized?...or the BackgroundWorker() TYPE is not being recognized?

What is the error?...
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 35199219

The Type
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35199251
You can either fully qualify the BackgroundWorker like this:


Or add an Imports statement to the top of your code:
Imports System.ComponentModel
Public Class Form1

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim CalcEstq As BackgroundWorker = CType(sender, BackgroundWorker)
        ' ...
    End Sub

End Class

Open in new window


Author Comment

ID: 35201885
Finaly the routine works, but the time out remains. I´ve tried to change my string connection adding Connect time out= 600. I´ve changed the number of seconds several times, Sometimes i´ve put large nummbers, but, in spite of this I can´t avoid the time out.

I can´t undertand the reason of the time out because the process is executed in background.

LVL 86

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 35202116
They are two completely different kinds of errors.

Your original error had to do with the long task blocking the message pump (which the backgroundworker fixes).

The second error has nothing to do with being in the foreground or background thread, and is really a function of the way the database call works.  I don't know how to fix that as I'm not a database guy...

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question