Static Finalizer

后端 未结 5 900
无人共我
无人共我 2020-12-08 00:40

What is the right way to perform some static finallization?

There is no static destructor. The AppDomain.DomainUnload event is not raised in the defaul

5条回答
  •  Happy的楠姐
    2020-12-08 01:09

    Two solutions that jump to mind:

    • Don't use a static class. If you use a non-static class and instantiate it, you don't have to worry about cleanup as much.
    • If that's not an option, I'd argue that this is a good situation to use a singleton. This will instantiate a copy of your object and have the finalizer called on exit, but still allow you to treat it like a static class for the most part. After all, your class is static already and therefore shares most of the common reasons not to use a singleton.

提交回复
热议问题