amibar / SmartThreadPool

A .NET Thread Pool fully implemented in C# with many features
http://www.codeproject.com/Articles/7933/Smart-Thread-Pool
Microsoft Public License
507 stars 182 forks source link

Add ability to wait for Thread to Abort #36

Open MichelZ opened 7 months ago

MichelZ commented 7 months ago

We have the need to wait for a cancelled work item to be aborted, so here's the ability to join to the aborted thread until it exits or there is a timeout

amibar commented 7 months ago

Hi,

You shouldn't rely on Thread.Abort() in your code. It is even not supported in latest .net core versions see https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.abort

Check the PostExecuteWorkItemCallback delegate to know when a work item completed (successfully or cancelled). You can use the event SmartThreadPool.OnThreadTermination to know when a thread is terminating. You can check if a work items is cancelled during its execution using SmartThreadPool.IsWorkItemCanceled

Also note that the code build fails, probably on missing modified file in the commit.

Ami

MichelZ commented 7 months ago

Hi,

You shouldn't rely on Thread.Abort() in your code. It is even not supported in latest .net core versions see https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.abort

Yes, I know. Unfortunately we don't have a choice here as we're calling thirdparty code with no cancellation support, and it sometimes just hangs.

Also note that the code build fails, probably on missing modified file in the commit.

Right. Fixed