处理并发文件写入 [英] Handling concurrent file writes

查看:114
本文介绍了处理并发文件写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个ASP.NET应用程序,需要用户输入,并将其序列化到一个文本文件中。现在,当第二次更新请求到来而该文件仍然被写入,一个IOException将会产生。

I am developing an ASP.NET application that takes user input and serializes them into a text file. Now, when a second update request comes while the file is still being written, an IOException will be generated.

我如何处理并发更新请求到这个文件?

How do I handle concurrent update request to this file?

推荐答案

您可以实现生产者 - 消费者,凡主线程将对象添加到队列,而消费者写入队列到磁盘

You can implement a Producer - Consumer, Where the main thread adds the object to a Queue, and the Consumer writes the Queue to the Disk.

这篇关于处理并发文件写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆