tig*_*tig 5 c# tcpclient async-await
以下代码按我的意愿工作,但会引发警告:
Warning 1 Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
是否有一个替代方案Task.Run()将以一种简洁的方式启动这个线程?
/// <summary>
/// StartSubscriptionsAsync must be called if you want subscription change notifications.
/// This starts the subscription engine. We always create one subscription for
/// Home DisplayName to start (but ignore any updates).
/// </summary>
public async Task StartSubscriptionsAsync(){
await _subscriptionClient.ConnectAsync(Host, Port);
// Generates a compiler warning, but it is what we want
Task.Run(() => ReadSubscriptionResponses());
// We do a GetValue so we know we have a good connection
SendRequest("sys://Home?f??" + "Name");
if (FastMode) EnableFastMode();
foreach (var subscription in _subscriptions) {
SendSubscriptionRequest(subscription.Value);
}
}
Run Code Online (Sandbox Code Playgroud)
dtb*_*dtb 12
当您既没有Task.Run方法返回await的Task也没有将它存储到我以后,就会触发警告.如果你想要发射冒险行为,你可以简单地存储任务但不能存储它:awaitawait
Task task = Task.Run(() => ReadSubscriptionResponses());
Run Code Online (Sandbox Code Playgroud)