Multi-thread to pupulate data in

Posted on 2011-10-06
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?

Question by:MikeDFarrant
    LVL 74

    Accepted Solution

    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.


    Author Comment

    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.

    Author Closing Comment

    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.
    LVL 74

    Expert Comment

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

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 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