SmartThreadPool icon indicating copy to clipboard operation
SmartThreadPool copied to clipboard

Add ability to wait for Thread to Abort

Open MichelZ opened this issue 1 year ago • 2 comments

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

MichelZ avatar Nov 17 '23 11:11 MichelZ

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

amibar avatar Nov 17 '23 15:11 amibar

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

MichelZ avatar Nov 17 '23 19:11 MichelZ