写从多个线程异步C#中的文件 [英] Write to a file from multiple threads asynchronously c#

查看:155
本文介绍了写从多个线程异步C#中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的情况。我想就写入文件系统尽可能有效地在我的应用程序。该应用程序是多线程的,每个线程都不可能写入同一个文件。有没有办法,我可以写从每个线程异步的文件,而无需在不同的线程爆炸头一起写的方式,可以这么说?

Here is my situation. I would like to make writing to the file system as efficient as possible in my application. The app is multi-threaded and each thread can possibly write to the same file. Is there a way that I can write to the file asynchronously from each thread without having the writes in the different threads bang heads together, so to speak?

我使用C#和.NET 3.5和我有安装了无功扩展为好。

I'm using C# and .NET 3.5, and I do have the Reactive Extensions installed as well.

推荐答案

有一个看的异步I / O 。这将释放CPU能够继续执行其他任务。
酒店与结合<一个href=\"http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlock.aspx\">ReaderWriterLock作为@Jack乙灵动通过

Have a look at Asynchronous I/O. This will free up the cpu to continue with other tasks.
Combine with ReaderWriterLock as @Jack B Nimble mentioned

If by

写入到文件系统作为
  尽可能高效

writing to the file system as efficient as possible

你的意思是使实际的文件I / O尽可能快你将有一个很难加速起来了,磁盘仅仅是身体上更慢。也许SSD的?

you mean making the actual file I/O as fast as possible you are going to have a hard time speeding it up much, disk is just physically slower. Maybe SSD's?

这篇关于写从多个线程异步C#中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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