Solved

How do avoid time out expired in my VB 2008 aplication

Posted on 2011-03-23
7
915 Views
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.

Thanks.

0
Comment
Question by:JGonzaga
  • 4
  • 3
7 Comments
 
LVL 85

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:
http://msdn.microsoft.com/en-us/library/8xs8549b.aspx
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
0
 

Author Comment

by:JGonzaga
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
0
 
LVL 85

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?...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:JGonzaga
ID: 35199219
Sorry!

The Type
0
 
LVL 85

Expert Comment

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

    System.ComponentModel.BackgroundWorker

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

0
 

Author Comment

by:JGonzaga
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.

Thanks.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 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...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now