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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:53:26+00:00 2026-06-03T19:53:26+00:00

I currently work to implement a singleton class with a couple of methods. Each

  • 0

I currently work to implement a singleton class with a couple of methods. Each method use the same private field that is in fact a connection to a database. In each methods, a reader is trying to be open. As you can see, this is a single connection shared in the entire scope of the application. If you try to open a reader connection in Ado.Net when a reader has already opened, an exception occurs. This case can open if you forget to close a reader after open it but it occurs in my case because I use multiple threads to do some things.

My question is: Must I implement a different mutex object for each method or a single one shared for all methods is enough?

I know that the singleton rarely a good pattern. I also know that a shared connection is not a good practice but remember that my project is a winforms project and is considered legacy. My client also don’t want to paid for a redesign of the application. I just want an answer about how the mutex should be handle in this case.

Thank you very much for your time.

  • 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-03T19:53:27+00:00Added an answer on June 3, 2026 at 7:53 pm

    You need a single mutex. If you have more than one mutex controlling a single shared resource (in this case a database connection) then more than one thread can access it at once, which defeats the point of a mutex.

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

Sidebar

Related Questions

I currently work in an organization that forces all software development to be done
I'm currently trying to implement a feature in my app that shows tags for
I am currently trying to implement a serial port reader class using Windows (already
I currently work at a company that has a lot of custom applications that
I'm currently trying to implement a destroy/remove method for views but I can't get
I am currently trying to implement the built-in Silverlight 3 validation against objects that
I currently work on a magento webshop, which loads PrototypeJS as framework. However i
I currently work in an environment where reports must be emailed to users as
I currently work with both Visual Studio, Eclipse/Rad, and Vim heavily. Visual Studio and
I currently work in the position of Data Warehouse programmer and as such have

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.