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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:07:59+00:00 2026-06-14T10:07:59+00:00

I have an application that uses an XML file to store certain data that

  • 0

I have an application that uses an XML file to store certain data that does not need to be in the DB. This file, while rarely, might be written to between pages at the same time. This creates an issue, most probably causing one of the pages to crash. I was wondering if there is a way to have a page render wait until the other is done writing to the file.

I am not sure if I can assume that every page render runs in its own thread; if it does, then can I halt that thread like a lock() command to wait for the resource to be available. If so, how can I implement a lock() on a file (since its not a memory segment)?

If its not threaded or I cannot use lock(), what other ways are there to make sure that the file is written to, but if someone else is using that file, it can wait for the file to be available?

There are a lot of methods of managing write order and rights but for this it is simple; if you came second, you will write in after the other person is done. I am not so concerned with write collisions at this point, but concurrent writing is something that needs to be addressed.

Any help is greatly appreciated!

  • 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-14T10:08:01+00:00Added an answer on June 14, 2026 at 10:08 am

    If it’s from a single machine, you could use a Semaphore http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx:

    private static Semaphore _fileSemaphore = new Semaphore(1, 1, "myFileGlobalSemaphore");
    
    // later...
    
    try
    {
        _fileSemaphore.WaitOne();
        // do stuff..
    }
    finally
    {
        _fileSemaphore.Release();
    }
    

    That’s kind of like a system-wide lock. Not great though, would suggest a DB. Plus, other things might cause file access to fail. You could implement something which creates a FileStream with the appropriate locking mode, which will fail if you try to open for writing by two sources, but it won’t do a lock-like scenario (which uses the Monitor class internally)

    Btw: “does not need to be stored in the DB”. The fact you’re asking this question suggests it really should be. If that’s a pain to implement, you might want to rethink your data access strategy. Stuff like Entity Framework w/ Code First makes it very easy to “chuck” stuff in the DB.

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

Sidebar

Related Questions

I have an application that uses an .xml file to load information about objects
I have an application that uses xml config file, where I'm describing layouts for
I have a C# application that uses XML digital signatures to sign license files.
I have an Android library project and the main application that uses this library
I have an application that 1) loads an xml, 2) uses a repeater (named
We have a web application that saves survey data in XML format, rather than
I have built an application that generates a large XML file using Linq-to-Entities and
I have a web application written in JSF2 that uses Spring. I need to
I have an application X that uses another application Y in certain cases. X
I'm writing an application that loads in records from an XML file and uses

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.