I have a particular problem where my Starting of the Task (Line 13) never returns. But i dont want to await this. (and for propper cleanup waiting i want the refrence)
My Code is here: https://pastebin.com/4Zb1bzJX
Some Say this call should return, others say use "ConfiguraAwait"(no option since i will not be able to get the instance)
I am unsure how to do it the "right way". Just get it working would be easy with a _bufferWorker = Task.Factory.StartNew(()=> BufferWorker());
but this just feels hacky and not right, since just creating a delegate to invoke something that is already a Task seems wrong)
How should i go about this problem there? (Maybe Tasks arent even the way i want to go here, and just use old Threads?)
Full included code to make it more readable:
private async Task BufferWorker()
{
while (_working)
{
if(!_queue.TryDequeue(out var data)) continue;
await Task.Delay(_provider.BufferedDuration);
_provider.AddSamples(data, 0, data.Length);
}
}
public void Open()
{
_working = true;
_bufferWorker = BufferWorker();//this line never returns
}
public void Close()
{
_working = false;
_bufferWorker.Wait();
_bufferWorker = null;
}
EDIT: i added a comment on the line that never returns
IMPORTANT INFORMATION: i also added a line that i stripped=> if TryQequeue fails i continue the loop. This is important, since the Task will return if i hit the first await. With this i can solve(by just waiting 1 ms on top), but this would be also a hack.