相关疑难解决方法(0)

线程安全集合,没有订单,也没有重复

我需要一个线程安全的集合来保存没有重复的项目.ConcurrentBag<T>允许非唯一项,HashSet<T>并且不是线程安全的.在.NET Framework 4.5中是否有这样的集合?

.net c# collections concurrency thread-safety

18
推荐指数
2
解决办法
3747
查看次数

为什么ReadOnlyDictionary不是线程安全的?

我正在寻找一个可以从多个线程访问的只读字典.虽然ConcurrentDictionary暴露了这样的功能,但我不希望有开销和奇怪的API.

.Net 4.5虽然提供了这样的类,但文档指出只有静态调用才是安全的.

我想知道为什么?

concurrency dictionary immutability thread-safety .net-4.5

11
推荐指数
1
解决办法
1572
查看次数

如何以高效的方式编写1GB文件C#

我有.txt文件(包含超过百万行),大约1GB,我有一个字符串列表,我试图删除字符串列表中存在的文件中的所有行并创建新文件,但它正在采取很长时间.

using (StreamReader reader = new StreamReader(_inputFileName))
{
   using (StreamWriter writer = new StreamWriter(_outputFileName))
   {
     string line;
     while ((line = reader.ReadLine()) != null)
     {
       if (!_lstLineToRemove.Contains(line))
              writer.WriteLine(line);
     }

    }
  }
Run Code Online (Sandbox Code Playgroud)

如何提高代码的性能?

c# performance file

10
推荐指数
1
解决办法
1190
查看次数