I have a UI button called Load. It spawns a thread, which in turn spawns a task. There is a wait on the task, and if it expires the task gets cancelled. The Load button is n
private CancellationTokenSource _cancelTasks;
// this starts your process
private void DoStuff()
{
_cancelTasks = new CancellationTokenSource();
var task = new Task(() => { /* your actions here */ }, _cancelTasks.Token);
task.Start();
if (!task.Wait(5000)) _cancelTasks.Cancel();
}