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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:13:56+00:00 2026-05-10T16:13:56+00:00

I have a situation where I might have multiple instances of a program running

  • 0

I have a situation where I might have multiple instances of a program running at once, and it’s important that just one specific function not be executing in more than one of these instances at once.

Is this the proper way to use a mutex to prevent this from happening?

lock (this.GetType()) {     _log.Info('Doing Sync');     DoSync();     _log.Info('Sync Completed'); } 
  • 1 1 Answer
  • 3 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. 2026-05-10T16:13:56+00:00Added an answer on May 10, 2026 at 4:13 pm

    You said multiple instances of one application, so we’re talking about two program.exe’s running, right? The lock statement won’t lock across multiple programs, just within the program. If you want a true Mutex, look at the System.Threading.Mutex object.

    Here is a usage example:

    bool createdNew; using (Mutex mtx = new Mutex(false, 'MyAwesomeMutex', out createdNew)) {     try     {         mtx.WaitOne();          MessageBox.Show('Click OK to release the mutex.');     }     finally     {         mtx.ReleaseMutex();     } } 

    The createdNew variable will let you know whether or not it was created the first time. It only tells you if it has been created, though. If you want to acquire the lock, you need to call WaitOne and then call ReleaseMutex to release it. If you just want to see if you created a Mutex, just constructing it is fine.

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

Sidebar

Related Questions

Here's the situation: I have a web-based ticket application, multiple users. One problem that
I have situation, where running a query that filters by an indexed column in
I have a guice based app that now needs multiple instances of a given
I have a situation where a query might be called multiple times from multiple
I have a situation where I have multiple drop down lists that are hidden
Situation: I have some persons with certain skills and they can/might belong to more
In my situation, I have might have userA and userB logged on to google
We have situation where say we have four engineers that are working on software
I don't have a specific situation I'm dealing with, so consider this more of
Until now I used to think that a web-application can have only one dispatcher-servlet

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.