G
Guest
How can I kill or close a MessageBox that is shown in a thread that I later
abort? In the following code, the MessageBox will always stay open until
closed by the user, even when the other event terminates first and the main
WaitForData method returns!
static public void WaitForData()
{
WaitHandle[] w = new WaitHandle[] { new AutoResetEvent(false), new
AutoResetEvent(false) };
Thread t0 = new Thread(new ParameterizedThreadStart(LookForData));
Thread t1 = new Thread(new ParameterizedThreadStart(LookForUserOverride));
t0.Start(w[0]);
t1.Start(w[1]);
if (WaitHandle.WaitAny(w) == 0)
{
Console.WriteLine("Confirmed data received; proceeding.");
t1.Abort();
}
else
{
Console.WriteLine("User Cancelled Wait for data; proceeding.");
t0.Abort();
}
}
static void LookForUserOverride(Object finish)
{
MessageBox.Show("Continue without waiting for data?", "Waiting for
data", MessageBoxButtons.OK);
((AutoResetEvent)finish).Set();
}
static void LookForData(Object finish)
{
... // Don't return until we find data
((AutoResetEvent)finish).Set();
}
abort? In the following code, the MessageBox will always stay open until
closed by the user, even when the other event terminates first and the main
WaitForData method returns!
static public void WaitForData()
{
WaitHandle[] w = new WaitHandle[] { new AutoResetEvent(false), new
AutoResetEvent(false) };
Thread t0 = new Thread(new ParameterizedThreadStart(LookForData));
Thread t1 = new Thread(new ParameterizedThreadStart(LookForUserOverride));
t0.Start(w[0]);
t1.Start(w[1]);
if (WaitHandle.WaitAny(w) == 0)
{
Console.WriteLine("Confirmed data received; proceeding.");
t1.Abort();
}
else
{
Console.WriteLine("User Cancelled Wait for data; proceeding.");
t0.Abort();
}
}
static void LookForUserOverride(Object finish)
{
MessageBox.Show("Continue without waiting for data?", "Waiting for
data", MessageBoxButtons.OK);
((AutoResetEvent)finish).Set();
}
static void LookForData(Object finish)
{
... // Don't return until we find data
((AutoResetEvent)finish).Set();
}