I ran into a situation like this:
private async Task SomeMethod(Task<SomeType> dataTask)
{
var data = await dataTask;
// process data...
}
We have the VS-threading analyzer and this emit a warning: VSTHRD003 Avoid awaiting foreign Tasks
The solution is to somehow use a JoinableTaskFactory
, but I can't figure out a way to make this work with this situation. I understand that dataTask is running on a different context than in this method, but I'm not sure how a JTF is supposed to solve this. Should I create my own context to run the task and then pass this to SomeMethod()
to actually run it?
I have access to the calling method, so I can make changes there. Neither methods need the main thread so I guess I can ignore this warning, but I still want to know how to properly solve this warning.