Results 1 to 9 of 9

Thread: [2.0] Form on its own Thread.

  1. #1

    Thread Starter
    Member MasterEvilAce's Avatar
    Join Date
    Jul 2002
    Posts
    60

    [2.0] Form on its own Thread.

    Is there a good way to put a form on its own thread so the GUI doesn't lag out on large processing?

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] Form on its own Thread.

    I'm not sure if I understand your question very well but Forms and other controls painting is .NET built-in, so there is no way you can modify that unless you'd write them from scratch (which is near impossible)
    But you can go the other way and do the large processing in a separate thread
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    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] Form on its own Thread.

    One common method is to load two forms... a splash screen and the regular form. The regular form is invisible until its processing is complete, while the splash screen shows. Until processing is complete. Then switch.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] Form on its own Thread.

    And If you're processing happens after form_load you can use this.SuspendLayout(); and this.ResumeLayout(); to pause Form painting
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

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

    Re: [2.0] Form on its own Thread.

    You should supply a little more information about exactly what the issue is so people can advise what the best solution might be.
    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

  6. #6

    Thread Starter
    Member MasterEvilAce's Avatar
    Join Date
    Jul 2002
    Posts
    60

    Re: [2.0] Form on its own Thread.

    Alright, the problem is I have a server application written. During some processes, such as connecting to a database.. if that connection fails, it freezes the entire GUI until it timesout and errors. So I figured if i put the form on its own little thread, the GUI would still be fine, no matter what process would freeze up the application.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] Form on its own Thread.

    I suggest you put the DB layer in a separate thread, rather than the other way round.

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

    Re: [2.0] Form on its own Thread.

    The entire UI should be executed in the main thread. The idea is to perform potentially long-running operations in there own thread so, as penagate says, it should be the data access operation that gets performed in a worker thread.
    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

  9. #9

    Thread Starter
    Member MasterEvilAce's Avatar
    Join Date
    Jul 2002
    Posts
    60

    Re: [2.0] Form on its own Thread.

    Revisiting question..

    It doesn't really seem feasible to have a bunch of other threads running.. this is a server application where the console gets a lot of text input to it. Adding tons of stuff to it lags the GUI.. which in turn seems to lag other things.

    I need to carry on my GUI in its own thread.. I have two other threads going as well.. one for the network listener, and another for a game loop that continually runs. Ideally, those two threads will remain, with a new thread for the form, and if I understand correctly, all the other operations (usually small, short operations that are run a lot of times throughout the application) will be in the original thread.

    currently the form starts at startup and everything else loads around that. If there's a way to start a separate class and then start the form in a thread, and my other stuff from the original class as well, that would be great. Is there anyway to do this?

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