?
Solved

Multi-thread to pupulate data in Vb.net

Posted on 2011-10-06
4
Medium Priority
?
284 Views
Last Modified: 2012-05-12
How can I call a sub from a Timer but process that sub on a new thread?

I need to refresh screen display from a database every second but I want to still be able to drag the form or perform right click etc. on the form without it appearing to be jerky or slow.

The sub that I want to call every reads the database and populates labels and a datagridview on the main page.  Currently ths sub is being called from a Timer as a standard call, can this simply be swapped to be a mulit-thread.

I am aware that the labels etc. can only be updated in the original thread what about a datagridview that has been linked to a datatable?

0
Comment
Question by:MikeDFarrant
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 total points
ID: 36928973
I am aware that the labels etc. can only be updated in the original thread
Controls can be updated from other threads, but you have to invoke a delegate in order to do so. I'd say for your multi-threading purposes you can use a BackgroundWorker. You get some nifty events which you can handle in your UI layer and these, if you code things correctly, should allow you to forgo the aforementioned invoking.

See:  http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
0
 

Author Comment

by:MikeDFarrant
ID: 36947301
I did try background worker before with not a lot of success.  I will take a little deeper look via this link it may take a few days for me to get back to you whether I have been successful (I have a number of prority projects on the boil at the moment!!)  Isn't life wonderful!!

Thanks for your answer.
0
 

Author Closing Comment

by:MikeDFarrant
ID: 36968939
Thanks for your answer.  The Background worker was much easier than trying to setup a thread.

One thing to note is that one of my controls was a bound data-grid that was supposed to update as a result of the background process.  I could not get this to work...

I could have unbound the grid and populated manually I guess, but as I wanted to change the color of the row based upon a value in the table anyway, I thought I'd just create a control for each row, color it and place it onto a double-buffered panel... it works a treat.

Thanks, for your help.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36973308
Glad you got it sorted out  = )
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

850 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