Custom GUI - Abort and Restart Test Plan

Hi everyone,
I developed a custom GUI (WPF) to run my test plans. Currently I am working on a mechanism to abort a running test plan. The abort does work but when I try to start a new measurement, it does not start the sequencer. Here is my routine how to start and stop the test plan.

  • Start sequencer (TestPlanRun is a Task of TestPlanRun)

public Task< TestPlanRun > TestPlanRun { get; set; }

public TestPlan TestPlan { get; set; }

TestPlanRun = TestPlan.ExecuteAsync();

  • Abort test plan run

TapThread.Current.Abort();

Attached the tap thread object and token is shown just before a new measurement is started after the test plan has been aborted. The “IsCancellationRequested” property is still set to “true”. Do I have to reset the token manually? UnfortunatelyI didn’t find any mechanism to do so…

TAP Thread :

image

Abort token:

image

If anyone has an idea how to solve this problem that would be great and is very much appreciated.

Best regards.
David

2 Likes

@david.minker welcome the Forum!

I think all you need to do is handle your CancellationToken more explicitly. You can pass this to your ExecuteAsync method and then use the CancellationToken to cancel your test. This will allow you to retry/rerun:

TestPlan.ExecuteAsync(resultListeners, null, null, cancellationToken.Token);

Abort using

cancellationToken.Cancel();

2 Likes

I think it’s a little more complicated.

How exactly are you restarting? You should be running TestPlan.ExecuteAsync() for every run, and use the new Task that this returns. Just making sure you’re not trying to restart from the Task object. In fact, I would set this property to null whenever the run ends, if you’re not already doing so.

If you use what Brennen said, something to keep in mind is that a CancellationTokenSource can only be used once. So if you are using the _abortTokenSource as a private member variable or something like that, you’ll need to Dispose the old source and instantiate a new CancellationTokenSource whenever you abort and start again.

1 Like

Thank’s for the replies. I implemented the cancelation token directly in the “ExecuteAsync” call and it works as expected.

4 Likes