finally vs catch in thread abort

  • Thread starter Thread starter Eran.Yasso
  • Start date Start date
E

Eran.Yasso

Hi,

I wondering where should i use finally and where should i use catch?

I have a thread, which the thread dispatcher waits for the thread. if i
abort the
thread, an exception happens. why should i use finally and not catch as
below?

for exmple?

private void button1_Click(object sender, EventArgs e)
{
myThread = new Thread(myThreadDelegate);
myThread.Start();
}

void threadcreatore()
{
try
{
Workerthread Workerthreadob = new Workerthread();
Workerthreadob.thdRunnerEngine();
}
finally
{
MessageBox.Show("In finally");
}
}

private void button2_Click(object sender, EventArgs e)
{
myThread.Abort();
}

You can see good sample in
http://www.yoda.arachsys.com/csharp/threads/shutdown.shtml

thanks,
 
Using Abort to stop a thread is the worst possible, "brute force" way to do
this.
Mr Skeet's examples on threading are most elegant and quite "best
practices". Suggest you read more of his material.
Peter
 
Peter said:
Using Abort to stop a thread is the worst possible, "brute force" way to do
this.
Mr Skeet's examples on threading are most elegant and quite "best
practices". Suggest you read more of his material.
Peter

I am using the abort method because my thread is process.start() on
wait. the only way
to kill the thread while is systemWait command is the abort.
 
Rule of thumb, finally is always fired whether there is exception or no
exception.

This is a good place to do clean up. Even if you have something like
return inside try catch finally is executed.
 
Back
Top