# How to notify your custom threads with user aborts?

**URL:** <https://forum.opentap.io/t/how-to-notify-your-custom-threads-with-user-aborts/610>\
**Category:** Technical\
**Tags:** opentap-sdk\
**Created:** [February 9, 2022, 3:07pm UTC](https://forum.opentap.io/t/how-to-notify-your-custom-threads-with-user-aborts/610 "2022-02-09T15:07:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushik.santhanam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/kaushik.santhanam/32/208_2.png) [@kaushik.santhanam](https://forum.opentap.io/u/kaushik.santhanam)\
**Post date:** [February 9, 2022, 3:07pm UTC](https://forum.opentap.io/t/how-to-notify-your-custom-threads-with-user-aborts/610/1 "2022-02-09T15:07:25Z")

</div>

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](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken?view=net-6.0)

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [February 9, 2022, 5:14pm UTC](https://forum.opentap.io/t/how-to-notify-your-custom-threads-with-user-aborts/610/2 "2022-02-09T17:14:56Z")

</div>

Ya, this is a nice feature. I have a comment on how I use it [here](https://forum.opentap.io/t/how-to-handle-abort-from-a-test-step/333/3).

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [February 10, 2022, 3:45pm UTC](https://forum.opentap.io/t/how-to-notify-your-custom-threads-with-user-aborts/610/3 "2022-02-10T15:45:38Z")

</div>

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:

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

```
