Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Threads.Abort()

If a thread is running a function func1 that calls another function func2 inside it...

Then I called thread.Abort()

Will this stop func1 only
OR func1 and func2 and all the functions func1 has called??

Thanks

Edit: Here are more detail:

func1 is called in a new thread, it continuously calls func2 on regular basis...
func2 begin doing some work only if some array is not null.. it finishes it and return

When supervisor wants to save data, it aborts Thread of func1- and then makes array null, saves data, then fill in the array with new one.. and starts Thread with func1 again..

Sometimes exception is raised because array is null in func2.. so func1 abort did not affect func2

like image 658
Betamoo Avatar asked May 24 '10 20:05

Betamoo


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


1 Answers

Thread.Abort is not guaranteed to stop the thread and you should avoid using it if possible.

Calling this method usually terminates the thread.

Emphasis mine.

What it does is raise a ThreadAbortException in the target thread. If you catch this exception, the code will continue executing until it reaches the end of the catch block, at which point the exception is automatically rethrown. If you don't catch it, it is similar to a normal exception - it propagates up the call stack.

Assuming you don't catch the exception, all the code running in that thread will stop running. Other threads that were started from that thread will not be affected.

like image 184
Mark Byers Avatar answered Sep 23 '22 07:09

Mark Byers