Click here to Skip to main content
15,438,202 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

I come to you for some help. I have an application that uses ODBC to query our data warehouse (Teradata), and since the main query (macro) does take a few minutes to complete, I decided to implement multi-threading so that the main thread does not stalls.

The secondary thread is set to run in the background with below-normal priority. Since the results are to be displayed in a "pop-up" dialog, I perform all cosmetic actions at the Load event of the form which also starts a timer that after one second, starts the secondary thread.

In theory, my dialog should remain "responsive" while the secondary thread retrieves the result-set. How do I know it stalls? easy, the animated .gif I am using to "show" activity, freezes when the thread hits the DataAdapter.Fill() method.

Any ideas? should I post the key lines of code? or have you read similar stuff so many times that this is a piece of cake? :cool:

Thanks for your time.


What I can imagine is that you already set it to be the datasource of a datagrid (or any other UI component) and because you are updating the data, the UI control halts and waits for completion. With this method it prevents updates while executing an update (or any other action). I think you can prevent stalling by removing it as datasource for UI components.

Another scenario is that you construct a thread with the method you want to execute in another thread, but eventually call it directly anyway:
Dim t As Thread
t = New Thread(AddressOf BackgroundProcess)

Instead of:
Dim t As Thread
t = New Thread(AddressOf BackgroundProcess)

Otherwise... you could indeed post some code to make it easier to spot the problem :-D

Good luck!
Share this answer
Dalek Dave 12-Nov-10 4:22am    
Good Answer.
Hi E.F. Nijboer,

Thank you for your insight. What you remarked as "instead of:", is almost the exact implementation I had before the issue. Late this afternoon, while explaining the code to a fellow programmer, I realized what voided the multi-thread implementation.

Somewhere along the road, I decided to add a small routine to modify the form's text in order to "tell" the user which step of the process was being performed (common practice at this company). As I added it, I said to myself ...this will require the use of the InvokeRequired property and the Invoke method, so that I won't get the nasty "illegal cross-thread operation" message..., and somehow I had the great idea of encapsulating my ODBC call inside of it, therefore, it was being performed within the main thread making the app non-responsive. :doh:

Once I removed the ODBC call from the "Invoke script", it all came back to normal and the app once again works like a charm. :cool:

Have a great weekend.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900