CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Posts
    239

    [RESOLVED] [2008] Updating Form Variables during Thread

    I'm not sure exactly how to describe this. In VB6, there was a Timer command. I could create a variable of type Timer and loop until the current value for Timer exceeded the initial plus a given amount of time. This allowed me to update form variables while the timing loop was executing. How can I do something similar in .NET?

    Here is a sample of the VB6 code:

    Code:
        Dim StartTimer As Double
    
        StartTimer = Timer
        Do
    
            Call Sleep(100)
            txtFinalRefValue.Text = DVMread(SystemSetup.RefChannel)
            
        Loop While (Timer < (StartTimer + LeakTestTime)) And DoEvents()

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [2008] Updating Form Variables during Thread

    Code:
     Loop While (Timer < (StartTimer + LeakTestTime)) ' And DoEvents()
    Remove the DoEvents() from the loop, and it should work. That's not exactly the best way to do that.


    You can have a separate thread that updates a textbox separately from the main thread. They both run at once, but one doesn't hold back the other, like DoEvents would. (10x per second!)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2004
    Posts
    239

    Smile Resolved: [2008] Updating Form Variables during Thread

    I guess I just didn't realize that the Timer function still existed in .NET. Here's the final code...

    Code:
         Dim StartTimer As Double
         Dim LeakTestTime As Double = 5
    
         StartTimer = DateAndTime.Timer
         Do
    
            Threading.Thread.Sleep(100)
            txtFinalRefValue.Text = DVMread(SystemSetup.RefChannel)
            Application.DoEvents()
         Loop While (DateAndTime.Timer < (StartTimer + LeakTestTime))

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

Featured