How to notify your custom threads with user aborts?

In some cases, you would be spawning new threads from the Test Step to run background tasks/polling tasks, etc. while the actual test step runs.

Is there a mechanism to safely notify the thread that the user has requested an abort of the test plan run?
Yes, TapThread class provides an AbortToken of type System.Threading.CancellationToken. You can pass this cancellation token to your threads and use the IsCancellationRequested property or more advanced callback mechanisms present in the CancellationToken class

3 Likes

Ya, this is a nice feature. I have a comment on how I use it here.

2 Likes

Recently I talked with some who needed to close a custom dialog when the thread was aborted. If you want to know exactly when a thread is aborted you can do like this:

var cleanMeUp = TapThread.Current.AbortToken.Register(() =>
{
     log.Info("This thread was aborted");
});
3 Likes