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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:15:16+00:00 2026-05-26T05:15:16+00:00

I am having a hard time figuring out what good a mutex is without

  • 0

I am having a hard time figuring out what good a mutex is without naming it. Specifically I want to make my Windows Mobile 6.5 app single-instance.

There are a few questions and answers on this site about how to do that – and the best ones seem to use named mutexes.

Unfortunately the CTORS for mutexes in compact framework do not take a string – one can only create a mutex.

Now, what good is a mutex if it has no associated ID?

Am I missing something?

How do I use a mutex to protect a resource across multiple applications if I can’t name them?

  • 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-26T05:15:17+00:00Added an answer on May 26, 2026 at 5:15 am

    In the compact framework itself, no there is not.

    What is the use for a Mutex if you can’t name it?

    An unnamed mutex is said to be a local mutex. You can still use it for synchronizing between different threads in the same process. A monitor like the lock keyword doesn’t have the same amount of functionality. As ctacke notes, a Mutex does not allow recursive entrance. Also, a monitor cannot be used across AppDomain boundaries. Additionally, a Mutex can be used with helpful things like WaitHandle.WaitAll or WaitAny, where a monitor cannot be used with any of those things.

    Am I missing something?

    No – In the .NET CF Framework you cannot name a mutex without the help of platform invoke.

    How do I use a mutex to protect a resource across multiple applications if I can’t name them?

    You have to name them – and you can do that, you just have to resort to some platform invoke. Windows CE based system have supported named mutexes for a while. You could write a P/Invoke call that does it yourself:

    [DllImport("Coredll.dll")]
    public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes, bool initialOwner, string lpName);
    

    And use it as (for example) CreateMutex(IntPtr.Zero, false, "MutexName");

    You would also have to write P/Invoke calls for ReleaseMutex and CloseHandle.


    Specifically I want to make my Windows Mobile 6.5 app single-instance.

    A named mutex is one solution. Another solution that may work for you is to use a file lock.

    1. Create a file named foo.txt on start up if it doesn’t exist.
    2. Acquire a write lock on the file file using FileShare.None.
    3. A different instance will not be able to aquire a write lock on it since the first instance has a lock on it and won’t share it. Catch the exception and terminate the program since one is already running.
    4. When the program closes, clean up the lock. Even if the process crashes or terminates abnormally, the lock on the file should be removed allowing another instance to start. Something like this:

      FileStream stream;
      try
      {
           stream = new FileStream("lock.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
      }
      catch
      {
          MessageBox.Show("Program is already running.");
          return;
      }
      //Put your application code here.
      MessageBox.Show("Program is now running.");
      stream.Close();
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a hard time figuring out good reasons for the dependency property.
I'm having a hard time figuring out what I'm doing wrong. I want do
Having a hard time figuring out how to make SASS, not SCSS, as the
I am having a hard time figuring out this problem. My app has iAds
Im having a really hard time figuring out how to specify a good search
Having a hard time figuring out the best way to do this... I have
I'm having a hard time figuring out how to architect the final piece of
I'm having a hard time figuring out how Firefox and Chrome determining what fields
I am having a hard time figuring out how to show an Image (or
I am having a hard time figuring out how to get the property list

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.