abort thread

  • Thread starter Thread starter one2001boy
  • Start date Start date
O

one2001boy

Hello,

is there a function to abort the running thread (thread-a) from another
thread (thread-b)?

thanks.
 
Hello,

is there a function to abort the running thread (thread-a) from another
thread (thread-b)?

thanks.

Sure sounds like a big time design problem if you have to resort to aborting
threads. How about providing a mechanism for orderly thread shutdown? It's
really pretty simple to do......

Mike P
 
Hello,
You may look to below code-snipp that is written C++.NET. There are 2
functions (Func_A, Func_B), and they are being run by 2 threads (Thread_A,
Thread_B). Thread_B will abort the Thread_A. Pay attention to
"ThreadAbortException" class. It is required at Func_A not to throw an
exception when Thread_B is aborting the Thread_A.

//Func_A is running by Thread_A
private:
void Func_A( )
{
try
{
// Do your work here ...
}
catch(ThreadAbortException *exp)
{
/*No need to do a work. Maybe write a message into log file.*/
}
catch(Exception *exp)
{ /*Catch other exceptions.*/ }
}

//Func_B is running by Thread_B.
void Func_B( )
{
try
{
...
Thread_A->Abort();
Thread_A->Join();
...
}
catch(ThreadAbortException *exp)
{...}
catch(Exception *exp)
{}
}


--
~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
Alper AKCAYOZ said:
Hello,
You may look to below code-snipp that is written C++.NET. There are 2
functions (Func_A, Func_B), and they are being run by 2 threads (Thread_A,
Thread_B). Thread_B will abort the Thread_A. Pay attention to
"ThreadAbortException" class. It is required at Func_A not to throw an
exception when Thread_B is aborting the Thread_A.

I would like to correct my word. Use "ThreadAbortException" class to catch
this type of expection when other thread aborts one thread. Aborted thread
will throw this exception and if you catch "ThreadAbortException" class, you
may do specific works when thread is aborted.
--
~~~~~~~~~~~~~~~~~~~
İyi Çalışmalar
Alper AKÇAYÖZ (Bil Muh)

Wish You Good Work
Alper AKCAYOZ (Bil Muh)
 
Back
Top