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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:28:00+00:00 2026-06-01T16:28:00+00:00

I am using an XML file to store the values. This XML file can

  • 0

I am using an XML file to store the values. This XML file can be accessed from multiple methods.

Private object lockObject = new object() 
Method1
 {
    Lock(this.lockObject)  
  {
      MyCommonMethod()  
  }
 } 
Timer.ElapseEvent 
{  
  Lock(this.lockObject)  
  {    
  MyCommonMethod()  
  } 
} 


   MyCommonMethod()
     {  
 // Read/Write to XML file.  
 var element = XElement.Load(path);  
 // some operations  

   element.save(path) 
} 

Now, this class is been used by multiple projects(Services) which in turn are combined in to a single project.

Can i use STATIC lock object in a class and will it work in this case of different processes??

So there are possibility that they use the file at same time and at times it gives me the error that different thread owns the file although i’ve kept the LOCK.

what could be the best solution in this senario?
Please guide.


How about this link …

Is there a way to check if a file is in use?

is this the best way to go for or i should go with Mutex??

Please guide..

  • 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-01T16:28:01+00:00Added an answer on June 1, 2026 at 4:28 pm

    A static variable will not be shared among difference processes.

    You can either:

    1. lock the file itself (pass the FileShare.None to FileStream constructor, then use that stream for reading XML), or
    2. use a global mutex (pass the non-empty name to Mutex constructor).

    The option (1) will not block in case file is already locked (it’ll just throw the exception immediately) – you’ll have to “poll” the file repeatedly if you want to emulate the blocking behavior. On the other hand, the option (2) will work only as long as your application is the only one accessing the file. Pick your poison.

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

Sidebar

Related Questions

I am using an XML file to store the values. This XML file can
I have an XML based file format that I'm using to store and load
I'm trying to extract some information from an xml file using xslt. I've used
I've succesfully loaded and parsed this XML file, using XMLParser and AS2: <Resources> <item
I'm using an xml file to store configurations for a software. One of theese
I'm using simpleXML to parse this xml file . It's a feed I'm using
I am using XML file for creating Context Menu for my ListView. (Please see
While loading an XML file in SSIS using an XML source component , i
I am using the XML::Simple module to parse an XML file. When I run
I have a ListView that is populated using an XML file. However, I want

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.