我正在使用一个不使用的多线程库,async
而是使用传统的线程和回调。
var connection = new SomeLib();
connection.OnConnected += (x) => { /* This is called from separate thread */ }
connection.Connect();
我从async
函数调用此代码,如下所示:
public async Task<Boolean> MyFunc()
{
var connection = new SomeLib();
connection.OnConnected += (x) => { /* This is called from separate thread */ }
connection.Connect();
// ...
// Need to return after OnConnected has been fired.
return true;
}
如何await
让我的函数“等待”OnConnected
回调被调用?