小编tuc*_*aff的帖子

多线程锁读/写文本c#

经过大量的研究,在阅读并尝试了所有问题后,我认为是时候向我寻求帮助了.

我在C#中有一个应用程序,我正在尝试使用不同的线程在SAME文件中编写.

public static void LaunchThreads(string path_file)
{
    int i = 0;
    Dictionary<int, Thread> threadsdico = new Dictionary<int, Thread>();
    while (i < MAX_THREAD)
    {
            Thread thread = new Thread(() => ThreadEntryWriter(string path_file));
            thread.Name = string.Format("ThreadsWriters{0}", i);
            threadsdico.Add(i, thread);
            thread.Start();
            i++;
    }
    int zz = 0;
    while (zz < threadsdico.Count())
    {
        threadsdico[zz].Join();
        zz++;
    }
}
private static readonly Object obj = new Object();
public static void ThreadEntryWriter(string path_file)
{
    int w = 0;
    while (w < 99)
    {       
        string newline = …
Run Code Online (Sandbox Code Playgroud)

c# multithreading locking thread-safety c#-4.0

5
推荐指数
1
解决办法
737
查看次数

标签 统计

c# ×1

c#-4.0 ×1

locking ×1

multithreading ×1

thread-safety ×1