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...