Results 1 to 3 of 3

Thread: Thread Troubles (CF)

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Thread Troubles (CF)

    Using the Compact Framework.

    I'm quite new to .NET and the CF and threading in general. Hope I can get some insight.

    I have an app that tries to connect via TCP. Since I want the GUI to be responsive when attempting to connect, I create a thread and start the Connect() method.

    My problem is, the Connect() method attempts to change the visibility of ToolBar buttons. If the current Visibility is False and I try to change to True, the Connect() method hangs, also, the GUI is not responsive.

    I'm guessing I'm creating a deadlock. Any help is appreciated.

    Mike

  2. #2
    Lively Member
    Join Date
    Sep 2003
    Location
    Chicago, IL
    Posts
    64
    You cannot mess with controls in a thread. if you do, all bets are off and it will most likely not work. I assume this is what you are doing when you say:

    "the Connect() method attempts to change the visibility of ToolBar buttons."

    What I would do is have a variable, called InThread lets say

    when a user clicks connect, set this to true and start a timer (ie timer is disabled by default and you enable it), along with your thread. In the timers tick event, check the value of InThread. If it is true, toggle visibility. When your thread is done working it can change the value of InThread to false and then when the timer fires again it will see false. Now you code timer.enabled to false and toggle your visibilty again. Something like this would work for the tick event as well:


    control.visible = Not InThread
    timer.enabled = InThread

    that way when the thread is done, you shut off the timer and show your hidden controls again
    Mike Stammer

  3. #3

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Cool, thanks, good to know. I was just banging my head trying a work-around, which was messing with another control. Of course that didn't work either.

    If I understand you correctly, a thread can mess with variables, but not controls?

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