I extended my method to async
, but i would like to have the possibilty to cancel by user request and timeout time, but WriteLineAsync
doesnt support handover of cancellation token. I tried nested Tasks, but doesnt work. Somebody can support me?
public async Task tapAsync(int x, int y, int timeouttime)
{
CancellationTokenSource cts;
cts = new CancellationTokenSource();
await Task.Run(async() =>
{
try
{
cts.CancelAfter(timeouttime);
await myWriter.WriteLineAsync("input tap " + x.ToString() + " " + y.ToString());
await myWriter.FlushAsync();
await Task.Delay(2000);
}
catch (OperationCanceledException)
{
Console.WriteLine("canceled");
}
}, cts.Token);
cts = null;
}