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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:06:05+00:00 2026-05-17T02:06:05+00:00

I have a couple applications running in separate processes that each write to a

  • 0

I have a couple applications running in separate processes that each write to a central xml doc on the harddrive. I am using a named mutex to synchronize access to the file – but get the following exception often:

System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.

I realized that I am calling the File.Exists() method before obtaining a lock on the mutex, is it possible that this could be the cause?

More simply, can anyone confirm if that method does a Read on the file to check if it exists? Im wondering if I need to lock the mutex before checking if the file is present.
I did verify that there is no AV software running, as that seemed to be common with this exception.

Rough example of current code:

private bool UpdateFile(string Text)
{
  if (!File.Exists(@"C:\FileName.xml"))
    return false;
  else
  {
    using (Mutex mutex = new Mutex(false, "ExampleMutexName"))
    {
      mutex.WaitOne(); 
      //Write to the file
      mutex.ReleaseMutex();
    }
    return true;
  }
}

EDIT: I was not using a global mutex because everything runs inside the same user account – so I believed a local mutex would be fine. However, one of the processes I start is with impersonation – which is why I SHOULD have used a global mutex. My mistake was just thinking that everything runs with in the same user account and would be fine.

  • 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-17T02:06:06+00:00Added an answer on May 17, 2026 at 2:06 am
    1. File.Exists returns false in case of errors and does not throw. It does not read the contents of the file though it checks for read permissions.
    2. It does not make a lot of sense to check if file exists before locking the mutex because it results in race conditions. File could be removed etcetera by someone else after your check and before your mutex is locked.
    3. The mutex you are using is not global, thus there is no guarantee that another application of the same kind is not modifying the file in parallel. Even if it was global, there is a problem when some application does not honor the lock. The best way to go here is to use file locking. See Lock and Unlock.
    4. The error you see basically means that file is opened by another process, suggesting a memory-mapped region.

    P.S.: It would also be nice to exclude this file from indexing service.

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

Sidebar

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.