小编Syl*_*voo的帖子

这个异步/等待代码导致潜在的死锁?

我有以下课程:

public abstract class ServiceBusQueueService : IServiceBusQueueService
{
    private readonly string _sbConnect;

    protected ServiceBusQueueService(string sbConnect)
    {
        _sbConnect = sbConnect;
    }

    public async Task EnqueueMessage(IntegrationEvent message)
    {
        var topicClient = new TopicClient(_sbConnect, message.Topic, RetryPolicy.Default);
        await topicClient.SendAsync(message.ToServiceBusMessage());
    }
}
Run Code Online (Sandbox Code Playgroud)

正在使用的是这样的:

public ulong CreateBooking()
{
     // Other code omitted for brevity 
     ulong bookingId = 12345; // Pretend this id is generated sequentially on each call

      _bookingServiceBusQueueService.EnqueueMessage(new BookingCreatedIntegrationEvent
      {
            BookingId = bookingId
      }).GetAwaiter().GetResult();

      return bookingId;
}
Run Code Online (Sandbox Code Playgroud)

EnqueueMessage从我的CreateBooking方法调用该方法时,该程序挂起并且在点击该行之后不再继续await topicClient.SendAsync(message.ToServiceBusMessage());

现在代码工作,当我将调用更改为my …

.net c# multithreading async-await azureservicebus

0
推荐指数
1
解决办法
316
查看次数

标签 统计

.net ×1

async-await ×1

azureservicebus ×1

c# ×1

multithreading ×1