1 回答

TA贡献1911条经验 获得超7个赞
如果您想SendRequest()在收到响应之前阻止完成,您可以使用 aSemaphoreSlim而不是在 a 中添加和删除键HashSet,例如:
public async Task SendRequest()
{
var topic = "SomeTopic";
SemaphoreSlim semaphoreSlim = new SemaphoreSlim(0, 1);
var responseHandler = new Action<ResponseMessage>(response =>
{
//signal that the response has arrived
semaphoreSlim.Release();
});
bus.Subscribe(BusController.ManualRequest, responseHandler, configuration => configuration.WithTopic(BusController.ManualRequest));
bus.Publish(someRequest, topic);
//wait for the response to arrive
await semaphoreSlim.WaitAsync();
semaphoreSlim.Dispose();
}
- 1 回答
- 0 关注
- 101 浏览
添加回答
举报