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

  • SEARCH
  • Home
  • 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 626727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:27:00+00:00 2026-05-13T19:27:00+00:00

I have a Singleton class that manages the connection to an external device. The

  • 0

I have a Singleton class that manages the connection to an external device. The idea of my application is that I need that external device to be presented all the time when the application is alive.

The Singleton has the following functionalities:

  1. Initialization, look for the device at the application startup time
  2. communicate with the external device, note that this can spread over multiple assemblies at multiple points.
  3. Close the connection when the application exits.

For the last part, I am thinking about putting the code inside Dispose method of the singleton class, to guarantee that the resource is always cleanup upon closing. But since I am using a Singleton, and since singleton life span will only be terminated when the application exits, there is no need to explicitly close the connection in Dispose since the connection will be close anyway.

So, the question is, should I put the close connection code inside Dispose method?

  • 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-05-13T19:27:00+00:00Added an answer on May 13, 2026 at 7:27 pm

    Implementing IDisposable alone doesn’t mean Dispose will be called on exit.

    Not enough details to understand your application but if closing incorrectly leaves the device in a bad state than maybe a try/finally or as Moron suggested Application.Exit (depending on the application of course).

    Even then you’re not guaranteed that code executes so maybe I’m not clear as to what you are trying to accomplish or what problem you are trying to solve.

    Edit:

    Per the OPs comment the best option (for his desire to have “cleanup” code execute without being specifically called and untestable) would be to put it in the deconstructor/finalizer. Note this is not guaranteed to run but should run in most circumstances without being called (unlike Dispose):

    public class Foo
    {
        public Foo()
        {
            //Constructor
        }
    
        ~Foo()
        {
            // Deconstructor/finalizer
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object of some class that obeys the singleton pattern. I need
Assume I have a singleton class in an external lib to my application. But
I have a singleton called Singleton that manages certain variables needed across the application
I have a singleton class which manages data and database handling of my application.
I have a class that is a singleton. This singleton is instantiated using GCD
I have a Singleton that is accessed in my class via a static property
I have a class that is managed by ninject as a singleton that looks
I want to have singleton class that its object is not statically created. having
I have a singleton class called Manager that holds a list of object instances:
I have a simple Android application that uses an instance of a class, let's

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.