0

I have an async function which performs possibly long lasting request.

private Task Request(CancellationToken ct) => { some HTTP call }

I call this function inside a try-catch block like this:

try {
    await Request(CancellationToken.None);
}
catch (Exception ex) {
    await CleanupDb();
}

private Task CleanupDb() { call to local DB }

My app is delivered as a Windows service. I faced that if the service is stopped, a TaskCancelledException occurs inside Request. What happens next? How will catch block work then? From my app logs it looks like that the catch block was executed (the CleanupDb is the only one who could do a specific action). But I was not succesful to reproduce it. I added logging before and after CleanupDb, and I saw only before but not after...

Alexander
  • 119
  • 7
  • 2
    try to request additional time - https://stackoverflow.com/questions/13454054 | https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.requestadditionaltime?view=dotnet-plat-ext-7.0 – Rand Random Jun 26 '23 at 16:28

0 Answers0