Results 1 to 5 of 5

Thread: [RESOLVED] [2.0] real time display of data

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Location
    Taiwan
    Posts
    37

    Resolved [RESOLVED] [2.0] real time display of data

    right now, i need to write a form which need to be updated frequently.
    let say it every 3s i update it.

    what is the best technique to do this in WinForms ?

    Can i do this with the System.Timers.Timer class ?
    The timer class is in multithread environment.
    When i write some code, i got problem displaying updated data in control label. It says that label is being used by another thread and recommend me to use Console.WriteLine() to display updated data.

    Can i use control label instead of Console ? bcoz when other user (without vs2005) run my program, he/she wouldn't be able to see the result in written in console ? am i right here?

    sorry, its kind of mess here..>< any solution / idea ?

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] real time display of data

    It depends what kind of project you started. Sounds like you started a Console project.

    Start a new project but make sure you select "Windows Application" instead of "Console Application".
    I don't live here any more.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2006
    Location
    Taiwan
    Posts
    37

    Re: [2.0] real time display of data

    no, i use Windows application form, not console.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] real time display of data

    What type of Timer are you using? If you use a Windows.Forms.Timer then the Tick events will be raised in the UI thread. The upside of this is that you can access controls directly, but the downside is that if the UI thread is busy the Tick event handler will not be executed until it becomes free. If you're using a Timers.Timer then the Elapsed events can be raised either in the UI thread or a worker thread. If you add the Timer to a form in the designer then its SynchronizingObject property will be set to that form by default, which means that the Elapsed events will be raised in the UI thread, which owns the form's handle. If you create your Timer in code then its SynchronizingObject property will be Nothing by default, so the Elapsed events will be raised in a worker thread. The upside of this is that your event handler will be executed when you expect the event to be raised. The downside is that you have to use a delegate to access controls on the form. Even if you do that, you still have to wait until the UI is not busy before it can execute the method that you want to invoke. You can search for "invokerequired" with my user name for examples of using a delegate to make a cross-thread control access.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2006
    Location
    Taiwan
    Posts
    37

    Re: [2.0] real time display of data

    ouw..
    your post resolve all my problems.
    i've been using System.Timers.Timer class.
    i should use System.Windows.Forms.Timer,i guess that the most appropiate class for my WinForms application.

    with System.Windows.Form.Timer, i think wouldn't have cross thread problem anymore..

    thx a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width