Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:44:26+00:00 2026-06-01T02:44:26+00:00

I am indifferent if you are a VB.NET or C# or other .NET developer.

  • 0

I am indifferent if you are a VB.NET or C# or other .NET developer. Answers would be appreciated no matter what language. Really looking for an idea…

I have a FACTORY class like the following:

Public Class MyFactory
    Public Shared theStuffICreated as List(Of Stuff)
    Public Shared/Static Sub Create(...)
         ...
    End Sub

    Public Shared/Static Sub ThingsToDoWhenClassIsDestroyed()
         ...
    End Sub
End Class

How can I make sure that ThingsToDoWhenClassIsDestroyed() is called when this class is “Destroyed” by the finalizer. I understand that since everything is shared/static it never really was created, but isn’t there some footprint of it somewhere that needs to be destroyed? Assume this class can be used by multiple GUI and console applications and it is not feasible to make a call to MyFactory.ThingsToDoWhenClassIsDestroyed() in each GUI’s Dispose method. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:44:28+00:00Added an answer on June 1, 2026 at 2:44 am

    Application.ApplicationExit was a good start. AppDomain.CurrentDomain.UnloadDomain was a good start also but neither worked all the time. Application.ApplicationExit seems to work for GUI apps but not for console apps. I ended up using AppDomain.CurrentDomain.ProcessExit because that works for everything. So my code looks like this:

    Public Class MyFactory 
        Public Shared/Static theStuffICreated as List(Of Stuff)
        Shared/Static Sub New()
            AddHandler AppDomain.CurrentDomain.ProcessExit, AddressOf ApplicationExitHandler 
        End Sub
    
        Public Shared/Static Sub ApplicationExitHandler(ByVal s As Object, e As EventArgs)
            RemoveHandler AppDomain.CurrentDomain.ProcessExit, AddressOf ApplicationExitHandler
            ThingsToDoWhenClassIsDestroyed()
        End Sub 
    
        Public Shared/Static Sub Create(...) 
             ... 
        End Sub 
    
        Public Shared/Static Sub ThingsToDoWhenClassIsDestroyed() 
             ... 
        End Sub
    
    End Class 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read Scott Guthrie's Blog - ASP.NET MVC 3: New @model keyword in
I need to design an Islamic Prayer Time Widget using ASP.Net, C#. I have
I created a .NET class library in C# with some resources for localization and
I have a Visual Studio C# .NET project. I have two master templates. One
How do you localize ASP.NET + javascript + Silverlight? I would like to be
I have an ASP.Net webforms application that uses the .Net globalization features to deliver
I have a ASP.NET MVC 3 application using NHibernate over a PostgreSQL database. There
We have written clients in different programming languages (Java, .NET/Silverlight, Flash, Javascript) that communicate
I have an application developed using .net that needs to be installed in different
We have a VB.Net application which works fine in our tests in different Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.