2
Answers

Multiple User Synchronous in ASP.NET

Ask a question

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. 

 


Answers (2)