ASP.NET中的同步多用户请求 [英] Synchronous Multiple User Reuest in ASP.NET
问题描述
我正在创建一个Web应用程序,在该应用程序中,一个表单会更新XML文件.如果用户要编写另一位用户已准备就绪的XML,则会收到错误消息.如何逐个同步此请求.
我使用了Semaphore和Lock,但是它们都不起作用.
我用过锁
公共静态对象obj_Lock = new object();
私有void Button_Click(对象发送者,EventArgs e)
{
锁(obj_Lock)
{
Update_XML()
}
}
它对于两个用户来说效果很好,当多个用户访问此方法时,它会引发错误,该文件被另一个进程使用.
信号量
公共静态信号量sem_Dest_XML = new Semaphore(1,1);
私有void Button_Click(对象发送者,EventArgs e)
{
试试
{
sem_Dest_XML.WaitOne();
XML_Record obj_Record =新的XML_Record();
Update_XML();
}
终于
{
sem_Dest_XML.Release();
}
}
在Samaphore中,我没有得到序列,假设user_1首先单击,user_2单击第二,而User_3单击三.但是它在User_1中作为First执行,在User_3中作为Second执行,在User_2中作为Last执行.
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.
推荐答案
在打开文件之前,您根本无法使它可用.强制用户单击按钮以查看可用文件的列表,并在可用时刷新该列表.
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.
这篇关于ASP.NET中的同步多用户请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!