处理ASP.NET应用程序中的并发XML写入和读取

时间:2021-11-20 13:29:17

Each time a users visits my web site pages, several xml elements are written and removed from one predefined file.

每次用户访问我的网站页面时,都会从一个预定义文件中写入并删除多个xml元素。

Eventually there will be a situation, when on this same file a read and write operation will take place almost simultaniously. How do I handle concurrency in this case? Is there a special base class library class that can handle it for me?

最终会出现这种情况,当在同一个文件上时,读写操作几乎同时发生。在这种情况下如何处理并发?是否有一个特殊的基类库类可以为我处理它?

1 个解决方案

#1


1  

XML files will not do this for you. You could set up a synchronizing object: the simplest would be to have a common function that accesses the file and use the lock key word. Use a Mutex for inter-process synchronization.

XML文件不会为您执行此操作。您可以设置同步对象:最简单的方法是使用一个访问文件并使用锁定关键字的公共函数。使用Mutex进行进程间同步。

However, this will be a potential bottle neck.

然而,这将是一个潜在的瓶颈。

It may be time to start using a database.

可能是开始使用数据库的时候了。

#1


1  

XML files will not do this for you. You could set up a synchronizing object: the simplest would be to have a common function that accesses the file and use the lock key word. Use a Mutex for inter-process synchronization.

XML文件不会为您执行此操作。您可以设置同步对象:最简单的方法是使用一个访问文件并使用锁定关键字的公共函数。使用Mutex进行进程间同步。

However, this will be a potential bottle neck.

然而,这将是一个潜在的瓶颈。

It may be time to start using a database.

可能是开始使用数据库的时候了。