i need to execute a function after a specific amount of time, therefore i use this code.
_start = DateTime.Now;
await Task.Delay(_app.Settings.AudioFileStartVarianz.BaseSpan).ContinueWith(x =>
{
Console.WriteLine(DateTime.Now - _start);
});
Lets say i want to wait for exactly 0.04 seconds. My problem now is that it's not working precise enough. I get following output after calling the function 5 times:
- 00:00:00.0414220
- 00:00:00.0536098
- 00:00:00.0507841
- 00:00:00.0467757
- 00:00:00.0425790
if i use this code it works way better
_start = DateTime.Now;
Thread.Sleep(_app.Settings.AudioFileStartVarianz.BaseSpan);
Console.WriteLine(DateTime.Now - _start);
- 00:00:00.0405879
- 00:00:00.0404284
- 00:00:00.0402117
- 00:00:00.0404908
- 00:00:00.0409088
But now i have the problem, that the function is not running asynchronous, what is bad because i am playing an audio file (NAudio).
Any ideas how i can here wait async, so that my audio file is not stopping?
KR Manuel