Results 1 to 2 of 2

Thread: Pausing Background Thread Until Operation Completes

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Pausing Background Thread Until Operation Completes

    I'm launching a background thread and running a task in that thread that takes about an hour. That task must complete before the thread continues. So I'm pausing it by calling Application.DoEvents until the method returns a value. I'm not a big fan of Application.DoEvents though.

    So is there a better method to accomplish this task?

    Thanks
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Pausing Background Thread Until Operation Completes

    Something in that statement isn't parsing for me. Does the background thread launch another thread for the task? Is the task a different process?

    I'm not so keen on DoEvents, either, though sometimes it is the best solution. From what I think I understand about the question, the thread that has to wait is not the UI thread, so it can sit and do nothing without anybody noticing or caring. That would be possible if the task was a blocking one, such that you called it, then execution on that thread stopped until the task returned, or it would be possible if the task could raise an event. The former is better than the latter, in some regards, but either would work. If the task doesn't block, and doesn't raise an event, then there may be no very good solution. Spin waiting would be the worst solution, though, so avoid doing that.
    My usual boring signature: Nothing

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