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

查看:35
本文介绍了从多个线程异步写入文件 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,而且我也安装了 Reactive Extensions.

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

推荐答案

看看 异步 I/O.这将释放 CPU 以继续执行其他任务.
结合 ReaderWriterLock 作为@Jack BNimble 提到

If by

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天全站免登陆