我正在使用一个不使用的多线程库,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回调被调用?