Visual Studio 此应用程序处于中断模式
Visual Studio This application is in break mode
我正在这样做:
public async Task Update(Entity input)
{
ValidateUpdate(input);
await UpdateAsync(input);
}
public async void ValidateUpdate()
{
// Some Logic
int adminCount = await _dbContext.AdminEntities
.CountAsync();
if(adminCount == 0)
{
throw new AppUserException("The tenant must always have at least one admin.");
}
}
当我遇到异常时 visual studio 向我显示了它,但是当我单击“继续执行”时 VS 向我显示了一个页面“应用程序处于中断模式”。如果我再次单击“继续执行”,VS 将停止 运行 应用程序。
当我在我的应用程序的其他部分抛出相同的异常时,它只是作为我的 HTTP 请求的响应返回。我不明白为什么。
我发现了这个问题,这是因为我在没有将 void
return 类型更改为 Task
的情况下使我的方法异步,并且我没有等待验证。
这是固定的例子:
public async Task Update(Entity input)
{
await ValidateUpdateAsync(input);
await UpdateAsync(input);
}
public async Task ValidateUpdateAsync()
{
// Some Logic
int adminCount = await _dbContext.AdminEntities
.CountAsync();
if(adminCount == 0)
{
throw new AppUserException("The tenant must always have at least one admin.");
}
}
一时心急,忘记查基础了。当我不可避免地再次犯同样的错误时,我希望这至少能帮助别人或我未来的自己。
我正在这样做:
public async Task Update(Entity input)
{
ValidateUpdate(input);
await UpdateAsync(input);
}
public async void ValidateUpdate()
{
// Some Logic
int adminCount = await _dbContext.AdminEntities
.CountAsync();
if(adminCount == 0)
{
throw new AppUserException("The tenant must always have at least one admin.");
}
}
当我遇到异常时 visual studio 向我显示了它,但是当我单击“继续执行”时 VS 向我显示了一个页面“应用程序处于中断模式”。如果我再次单击“继续执行”,VS 将停止 运行 应用程序。 当我在我的应用程序的其他部分抛出相同的异常时,它只是作为我的 HTTP 请求的响应返回。我不明白为什么。
我发现了这个问题,这是因为我在没有将 void
return 类型更改为 Task
的情况下使我的方法异步,并且我没有等待验证。
这是固定的例子:
public async Task Update(Entity input)
{
await ValidateUpdateAsync(input);
await UpdateAsync(input);
}
public async Task ValidateUpdateAsync()
{
// Some Logic
int adminCount = await _dbContext.AdminEntities
.CountAsync();
if(adminCount == 0)
{
throw new AppUserException("The tenant must always have at least one admin.");
}
}
一时心急,忘记查基础了。当我不可避免地再次犯同样的错误时,我希望这至少能帮助别人或我未来的自己。