Updating of Winform UI every second

Posted on 2006-04-24
Last Modified: 2008-03-17
Hi, i have a UI which displays values (Around 40) and i have to update all the 40 values every second as there are chances..the values will be altered at any time. But creating a loop and updating the UI every sec..i figured out it will make the UI super unresponsive..or the UI won't even show up. I have tried using timers for such an app in vb6 and the result was an unresponsive UI. Are there any way i can create multiple threads to update my UI (i.e getting the threads to UI so that load can be shared instead of getting the main app thread to do it all) Some simple code sample would be best or links to resources and case studies regarding this. Thanks
Question by:jaxrpc
    LVL 48

    Assisted Solution

    Updating UI evry second by timer doesn't look like complicated task. I think that this is what you should do.
    Notice that worker thread cannot update UI directly, it must call UI function using Invoke or BeginInvoke function. Function which updates UI in any case runs in main application thread.
    You don't say anything about source of information. Worker thread can do some calculations, read data from some device or socket, but UI is always updated from amin thread.
    LVL 85

    Accepted Solution

    Encapsulate your Thread in a Class that raises a custom Event.  When the main form receives the Event, use a Delegate and the Invoke() method to marshal the call from the thread onto your main UI thread.

    Here are some examples:

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 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

    21 Experts available now in Live!

    Get 1:1 Help Now