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 7771449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:39:20+00:00 2026-06-01T16:39:20+00:00

I have used the singleton pattern to create a single instance of a web

  • 0

I have used the singleton pattern to create a single instance of a web service that I use in my win forms application. I have seen that this is good practice for web applications. I was wondering if this is the same for winform apps too? Also, should I worry about disposing of the web service (i.e. the proxy object afterwards) – it has a .Dispose method but I am not calling it anywhere in my code. In my application I am calling all my web methods asynchronously. This might sounds silly but I don’t know where I need to call dispose. Can anyone help?

class ListService
{
    private static RetrieveList s_proxy;

    private static readonly object s_lock = new object();

    private static readonly string s_webServiceURL = Authentication.RetrieveListUrl;

    internal static RetrieveList Proxy
    {
        get
        {
            lock (s_lock)
            {
                if (s_proxy == null)
                {
                    s_proxy = new RetrieveList();
                    s_proxy.Url = s_webServiceURL;
                }

                return s_proxy;
            }
        }
    }

}
  • 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-01T16:39:22+00:00Added an answer on June 1, 2026 at 4:39 pm

    If you have a single instance for an application, the object will be destroyed when the application closes or crashes. You could call Dispose in the finalizer, but that’s not guaranteed to succeed.

    Unless Dispose does something vital like saving your document (it shouldn’t), I’d say, don’t worry too much. The fact it is a singleton means it lives forever and disposing is only meant to free resources that would otherwise remain around. The object remains around, so nothing to free.

    However, some people may frown on this and say “what if the Dispose does something that is important to me, other than freeing resources?”. You can still call Dispose after your application has run:

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new LogAnalizzer());
        ListService.Dispose();   // or whatever you're going to call it
    }
    

    I have seen that this is good practice for web applications. I was wondering if this is the same for winform apps too?

    As a rule of thumb, when your application as a whole needs only one instance of something, a (thread safe) singleton is often a good idea: a cache, connection to a database, a proxy, the application itself, a logger. There’s nothing that says that singletons shouldn’t apply to your WinForm apps also.

    Remember however that you must carefully think about your design. What if you have a logger and the file becomes inaccessible? What if a proxy looses connection? etc, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java singleton class that has my application settings. I used this
I have a singleton that I use for creating an application wide report. As
I have a singleton instance that is referenced throughout the project which works like
I am fairly new to web programming, I have mainly used java to create
I have a singleton class which is being used throughout the app. I am
I have a question about the Singleton Pattern and MEF. I'm new in implementing
I have used singleton calss following the example: singleton class But i get the
We have used the Factory/Singlton pattern for creating a workflow runtime. When we run
I have a queue that should be used by some classes. it is the
I was confused when I first started to see anti-singleton commentary. I have used

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.