Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am creating a web application, in which a form update the XML file. I am getting an error if a user wants to write XML which is all ready writing by another user. How to synchronous this request one by one.
I used Semaphore and Lock, but either of them not working.
I used Lock
public static object obj_Lock = new object();
private void Button_Click(object sender, EventArgs e)
{
lock(obj_Lock)
{
Update_XML()
}
}
It is working well for two users, when multiple users access this method it raise a error, file used by another process.

Semaphore
public static Semaphore sem_Dest_XML = new Semaphore(1, 1);

private void Button_Click(object sender, EventArgs e)
{
try
{
sem_Dest_XML.WaitOne();
XML_Record obj_Record = new XML_Record();
Update_XML();
}

finally
{
sem_Dest_XML.Release();
}
}

In Samaphore I am not getting the sequence, suppose user_1 click first, user_2 click Second and User_3 Click Three. But it is executed in User_1 as First, User_3 as Second and User_2 as Last.
How to solve This.
Posted

1 solution

You could simply not make a file available until it can be opened. Force the user to click a button to see a list of available files, and refresh that list when they do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900