C# 多线程高并发的情况下,怎么让数据先到先执行?
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
ConcurrentQueue<string> _queue = new ConcurrentQueue<string>();
......
for (int indx = 1; indx <= 3; indx++)
{
string command = $"build.bat "{_curDir}" "{_versionInfo}" "{_args3[indx]}" "{_args4[indx]}" "{_args5[indx]}"";
_queue.Enqueue(command);
}
......
while (_queue.TryDequeue(out string cmd))
{
btnBuild.Dispatcher.Invoke(() =>
{
btnBuild.IsEnabled = false;
});
Thread thread = new Thread(Worker);
thread.IsBackground = true;
thread.Start(cmd);
}
......
private void Worker(object command)
{
Thread.Sleep(100);
// do same sth
}