G
Guest
Hi,
I create a worker thread to create a local CE database then connect to a
webservice to bring back data. This process runs in the business logic tier
which communicates to the client UI thread via a passed parameter. It
communicates with the UI thread to see if a cancel request has occured and
also to update the status (progress bar etc).
What I would like to know is how can I make the UI thread wait until the
worker thread has returned from the call to the web service in order to
perorm some further processing like deleting the CE database before control
is returned to the calling UI program.
I know it sounds confusing. Here is a snip of the UI cancel method:
private void cancel_push_Click(object sender, System.EventArgs e)
{
//Check if we are running any worker threads or not.
if (worker_thread!=null)
{
if (worker_thread.IsAlive)
{
worker_thread.Suspend();
DialogResult _result =
MessageBox.Show(MyResources.Strings["middleofcreatingalogbook_msg"],
this.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (_result==DialogResult.Yes)
{
//Then cancel the current operation.
Cache.ThreadStatus=WorkerThreadStatus.Exception;
//Resume the thread to let it finish doing its job.
worker_thread.Resume();
}
else
{
//Then continue.
worker_thread.Resume();
return;
}
}
}
//Ensure we disconnect from the Connection Manager.
if (connection_cm!=null)
{
connection_cm.OnConnectionStateChanged-=new
EventHandler(connection_cm_OnConnectionStateChanged);
connection_cm.Disconnect();
}
Close();
}
Formating of the above look real ugly!
Settting ThreadStatus enum tells the business logic we want to quit. At this
point the thread is resumed which does clean up like deleting the CE database.
I don't want control to return until this thread has finished. I tried a
while(worker_thread.IsAlive)
{
//wait
}
But this seems to use up so much processing power it takes forever for
control to return.
Regards
Simon.
I create a worker thread to create a local CE database then connect to a
webservice to bring back data. This process runs in the business logic tier
which communicates to the client UI thread via a passed parameter. It
communicates with the UI thread to see if a cancel request has occured and
also to update the status (progress bar etc).
What I would like to know is how can I make the UI thread wait until the
worker thread has returned from the call to the web service in order to
perorm some further processing like deleting the CE database before control
is returned to the calling UI program.
I know it sounds confusing. Here is a snip of the UI cancel method:
private void cancel_push_Click(object sender, System.EventArgs e)
{
//Check if we are running any worker threads or not.
if (worker_thread!=null)
{
if (worker_thread.IsAlive)
{
worker_thread.Suspend();
DialogResult _result =
MessageBox.Show(MyResources.Strings["middleofcreatingalogbook_msg"],
this.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (_result==DialogResult.Yes)
{
//Then cancel the current operation.
Cache.ThreadStatus=WorkerThreadStatus.Exception;
//Resume the thread to let it finish doing its job.
worker_thread.Resume();
}
else
{
//Then continue.
worker_thread.Resume();
return;
}
}
}
//Ensure we disconnect from the Connection Manager.
if (connection_cm!=null)
{
connection_cm.OnConnectionStateChanged-=new
EventHandler(connection_cm_OnConnectionStateChanged);
connection_cm.Disconnect();
}
Close();
}
Formating of the above look real ugly!
Settting ThreadStatus enum tells the business logic we want to quit. At this
point the thread is resumed which does clean up like deleting the CE database.
I don't want control to return until this thread has finished. I tried a
while(worker_thread.IsAlive)
{
//wait
}
But this seems to use up so much processing power it takes forever for
control to return.
Regards
Simon.