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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:37:55+00:00 2026-06-11T11:37:55+00:00

I have an app that creates an object that needs to be locked as

  • 0

I have an app that creates an object that needs to be locked as this object creates an external hardware device object (via third party DLL) and the hardware device object can only be created once. When multiple instances of this app are launched, only the first instance should be able to create this C# object. The subsequence instances should see that the object has been locked and object can not be created. I used a mutex as this object creation occurs in multiple app instances (multiple processes). The code doesn’t lock with the mutex however. Am I running multiple instances in which each one creates its own lock?

public sealed class MyObject
{
    private static MyObject _myObject;
    static ExtDeviceDriver devDrv;
    private readonly static Mutex mut = new Mutex();

    private MyObject()
    {
        mut.WaitOne();
        //Thread safe code here.
        devDrv = new ExtDeviceDriver();
    }

    ~MyObject()
    {
        mut.ReleaseMutex();
    }

    // object accessor
    public static MyObject GetMyObject
    {
        get
        {
            if (_myObject == null)
                _myObject = new MyObject();
            return _myObject;   
        }
    }
}
  • 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-11T11:37:57+00:00Added an answer on June 11, 2026 at 11:37 am

    I guess you should use named mutex (See this article on MSDN).

    Mutexes are of two types: local mutexes and named system mutexes. If
    you create a Mutex object using a constructor that accepts a name, it
    is associated with an operating-system object of that name. Named
    system mutexes are visible throughout the operating system and can be
    used to synchronize the activities of processes. You can create
    multiple Mutex objects that represent the same named system mutex, and
    you can use the OpenExisting method to open an existing named system
    mutex.

    So, try to use this constructor to create a named Mutex. Besides you should check, whether it already exists with Mutex.OpenExisting Method (Consider the example given in this very article; is tells how to check, create, utilize a named mutex).

    EDIT

    See Mutex Class:

    You can use the WaitHandle.WaitOne method to request ownership of a
    mutex. The thread that owns a mutex can request the same mutex in
    repeated calls to WaitOne without blocking its execution. However, the
    thread must call the ReleaseMutex method the same number of times to
    release ownership of the mutex. The Mutex class enforces thread
    identity, so a mutex can be released only by the thread that acquired
    it.

    And Mutex Constructor (Boolean, String), that says, that a bool argument must be set to:

    true to give the calling thread
    initial ownership of the named system mutex if the named system mutex
    is created as a result of this call; otherwise, false.

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

Sidebar

Related Questions

I have a desktop app that creates a graphics 2D object, sticks it in
Good day, I have created an object that will manage data access. My app
I have created an app in C# .Net 2.0 that uses the AxShockwaveFlash object
I have an app that creates a variable number of ScatterviewItems based on which
I have an app that creates a SQLite database ( with 24 records ),
I have an app that creates a database and do some stuff. I am
currently I have an app that creates all sorts of different requests to Facebook
I have a PHP app that creates a CSV file which is forced to
I have an ASP.NET Login App that creates a cookie called 'ASP_LOGIN77' and gives
I have an app that displays a splash screen. The splash screen activity creates

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.