• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Multi-thread to pupulate data in Vb.net

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
MikeDFarrant
Asked:
MikeDFarrant
  • 2
  • 2
1 Solution
 
käµfm³d 👽Commented:
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
 
MikeDFarrantAuthor Commented:
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
 
MikeDFarrantAuthor Commented:
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
 
käµfm³d 👽Commented:
Glad you got it sorted out  = )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now