我正在尝试使用以下代码来设置故障条件,即没有可用的网络路径,因此代码根本无法发送到服务总线。我知道这一点是因为我在测试时禁用了网络端口。
尽管如此,我仍然对代码的异步性质有疑问。我不知道在控制台应用程序中如何附加一些东西来注销我知道应该生成的异常。
如何查看异常文本?
public async Task TestQueueExists()
{
_queueClient = new QueueClient(AppSettings.McasServiceBusConnectionString,
AppSettings.ListServSyncQueueName);
Logger.Information(
$"Queue Created to: {_queueClient.QueueName} with RecieveMode: {_queueClient.ReceiveMode}");
try
{
await _queueClient.SendAsync(new Message("Test".ToUtf8Bytes()));
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
最佳答案
我遇到的问题是我使用的是控制台应用程序,并且控制台应用程序开箱即用地运行同步。我必须修改我的 Main
以返回 Task
并使用 async
来捕获异常,这是有道理的。
即
internal class Program
{
static async Task Main(string[] args)
{
[..]
}
}
关于c# - 在 Azure 服务总线 SendAsync 方法上捕获异常时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48026671/