dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: weird behavior...probably threading related

  1. #1
    Join Date
    Sep 2004
    Posts
    3

    weird behavior...probably threading related

    I wrote a control. It is a timer with 1 button (Start/Stop) and 3 readonly textboxes to show the

    start time, stop time, running time. It also has a public method Start() which is also used in

    the ClickEvent of the button to start the timer. While the timer is running, the textbox that

    shows the running time is updated every second.

    Here's the weird part. When Timer.Start() is called in another thread, the textboxes that should show the details are not updated on a certain interval. The reason why I put the call to Timer.Start() in another thread is that it's called by a remote host via sockets. The remote host sends its hostname which corresponds to a certain field in a set of MyTimer controls. The update is in the Tick event of a Timer control within my control. I tried putting messageBox routines and I did find out, they are not executed. The Tick event does not fire!!! The timer works fine when using the start button to start it. Is this due to the fact that the event occurs in the main thread?

    Please enlighten me about this weird behaviour.

  2. #2
    Join Date
    Sep 2004
    Posts
    52
    Be sure to invoke your Start method from the UI thread. To do so, use the Invoke method on your control from the other thread:

    yourControl.Invoke(...);

    HTH,
    Kent

    PS. google for "windows forms threading invoke" for more info.

  3. #3
    Join Date
    Sep 2004
    Posts
    3
    Hi Kent. Thanks so much for the reply. It works. You saved me a lot of time and energy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center