finally vs catch in thread abort

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,
 
G

Guest

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
 
E

Eran.Yasso

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.
 
Z

Zeya

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top