Results 1 to 5 of 5

Thread: [2.0] Thread trouble

  1. #1

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    [2.0] Thread trouble

    Hi. Im making a small socket app (im talking about the server by the way). All it does is wait for a connection, and when it recieves one, it displays a message from the client closes the connection, and then loops to wait for a new connection.
    I wanted to be able to have a button to stop the server at any time, but because the UI isnt responsive while waiting for a connection or in a loop, so i put the method into a thread, but the it uses textboxes that were created in another thread, so i cant do it that way.
    I apoligise if that wasnt clear.
    Can anyone help?

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

    Re: [2.0] Thread trouble

    You can do it that way. You can use a BackgroundWorker and call its ReportProgress method to raise the ProgressChanged event in the UI thread. You can then access any control directly from the ProgressChanged event handler. If you just want to mange the worker thread yourself then you simply use delegation to invoke a method on the UI thread from which you can then access your controls. Search the forum for my user name and the keyword "invokerequired" and you'll find an example.
    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

  3. #3

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [2.0] Thread trouble

    Im sorry but I'm not sure I understand.

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

    Re: [2.0] Thread trouble

    Have you done the search and read the code? Have you read about the BackgroundWorker class?
    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
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2.0] Thread trouble

    What if you simply pass the textbox values as the threading method's arguments?

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