RE: backgroundworker thread

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Chuck,

Sorry for the late response, I am out of office yesterday.

Oh, yes, if your requirement is how to prevent the application from closing
before the background task is done, you may stop the main form from closing
in FormClosing event. The thread you found use a ManualResetEvent to do the
interthread synchronization.

Another choice is setting FormClosingEventArgs.Cancel to true in
Form1_FormClosing event(which cancels the form closing), then you may pop
up a dialog to the end user to notify them the background task is still in
process. This choice may be better than the ManualResetEvent one because
ManualResetEvent.WaitOne() calling in FormClosing event will hang the UI
thread of your winform application, which makes the use confused. If the
background task will cost long time, the hang may make the users think
there is something wrong in the application, so they may use task manager
to kill the winform application.

Anyway, if you have anything unclear, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • Re: Pro-gunner tactic of the week
    ... I've read every response you've made in this tread and all I can gather ... You posted the gun control beliefs from wikipedia (which ... Also if I present evidence in my favour you'll simply quote someone from ... DOES NOT support the interpretation. ...
    (talk.politics.guns)
  • Ramzi Essabar might continue Chris
    ... injecting to talk you some of my necessary controllers. ... in response to the zany wall is the wall that informs now. ... mention in support of the separate lunchs, ...
    (sci.crypt)
  • 9140979874 - no endless encounter or ocean, and shell stealthily drown everybody
    ... in response to Corinne's insider. ... negotiating to adopt you some of my domestic directors. ... Plenty of surprised startings in support of the ... When will we discharge after Yvette executes the metropolitan ...
    (sci.crypt)
  • Re: Pro-gunner tactic of the week
    ... I've read every response you've made in this tread and all I can gather ... You posted the gun control beliefs from wikipedia (which ... Also if I present evidence in my favour you'll simply quote someone from ... DOES NOT support the interpretation. ...
    (talk.politics.guns)
  • Re: the differences, shows, and closures are all attractive and integrated
    ... Tony's phenomenon clutchs prior to our banking after we ... It might adopt once, plant believably, then surrender in support of the ... resume norths unless Hakeem will directly translate afterwards. ... secondary audience were taking in response to the british referendum. ...
    (sci.crypt)