Solved

How do avoid time out expired in my VB 2008 aplication

Posted on 2011-03-23
7
927 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
Independent Software Vendors: 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

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to open text file 11 136
Assigning VBA code to a specific worksheet 3 37
Adding a countdown to HTA 12 91
MS ACCESS 2010 Clear Form Button 4 60
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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