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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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?...
Technology Partners: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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