When constructing types or calling methods that accept a JoinableTaskFactory
or JoinableTaskContext
, take the opportunity to supply one if your application
has a main thread with a single threaded SynchronizationContext
such as WPF or WinForms.
void F() {
var o = new AsyncLazy<int>(() => Task.FromResult(1)); // analyzer flags this line
}
Call the overload that accepts a JoinableTaskFactory
or JoinableTaskContext
instance:
void F() {
var o = new AsyncLazy<int>(() => Task.FromResult(1), this.JoinableTaskFactory);
}
You can suppress the diagnostic by explicitly specifying null
for the argument:
void F() {
var o = new AsyncLazy<int>(() => Task.FromResult(1), null);
}