Replies: 2 comments
-
A finalizer isn't a secure way to dispose of instances, period. There's no guarantee that they ever get called. In particular:
This isn't going to happen. .NET Core already doesn't run finalizers when the application is gracefully shutting down (because the held resource will be released anyways), and an application crash may stop the process "immediately", not letting any further code run. Creating fault-tolerant applications is hard. You've mentioned network issues, but your application has no guarantee the network ever comes back, and any new actions you take at that point, like writing to a local file, can fail as well.
.... preferably, don't do this. It makes it harder to test your code, and creates hidden internal dependencies. That said:
Manually call |
Beta Was this translation helpful? Give feedback.
-
AppDomain.ProcessExit is a recommended API to do cleanup on shutdown. This thread has example: dotnet/docs#17463 (comment) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, team. We have some fixed number of static disposable instances that are throughout the lifecycle of the app process. These instances will force flush data to a backend service when dispose. We want to find a best way to dispose these static objects to handle graceful shutdown. Here are some thoughts from us:
Here are the questions:
Beta Was this translation helpful? Give feedback.
All reactions