c# - Warning when awaitable calls aren't waited/awaited -
c# - Warning when awaitable calls aren't waited/awaited -
this code causes exceptions lost.
instead of boo.dostuff()
, should task.waitall(bar.dostuff())
.
it's safe block because timer callback on thread pool thread, , i'm not doing utilize iocp. if don't block, silently lose exceptions.
how can either vs/resharper/something give me warning on line?
public class foo { readonly iboo _boo; readonly timer _timer; public foo(iboo boo) { _boo = boo; _timer = new timer(beat, null, timespan.zero, timespan.fromseconds(1)); } void beat(object state) { _boo.dostuff(); // <-- warning wanted here // task.waitall(bar.dostuff()); <-- should have written } } public interface iboo { task dostuff(); }
i don't know of tool provide warning resharper extensible. open-sourced code extension marks allocations in source code. seems not hard write extension. trigger on method calls homecoming task
, not utilize result of phone call in way.
you might face false positives, though, in cases method returns task polled error info elsewhere. still, useful warning. see questions on stack overflow solved not ignoring task.
c# async-await
Comments
Post a Comment