当直接调用与调用者位于同一程序集中的Async方法时,我们会收到预期的CS4014警告。但是,当从不同的程序集调用该方法时,不会给出警告。在VS2015中,AsyncStateMachineAttribute存在于元数据中,但是当intellisence显示警告时,不会使编译器产生警告。
public class Caller
{
public Task CallWorkAsync()
{
// This call will not generate a compile error
Class1 c = new Class1(); // from different Assembly
c.DoWorkAsync();
// This call will generate a compile error
var c2 = new InSameAssembly();
c2.DoWorkAsync();
return Task.FromResult<bool>(true);
}
}
public class InSameAssembly
{
public async Task DoWorkAsync()
{
await Task.Yield();
}
}