dan*_*n78 10 c# random multithreading
我有以下课程
class Program
{
static Random _Random = new Random();
static void Main(string[] args)
{
...
for (int i = 0; i < no_threads; ++i)
{
var thread = new Thread(new ThreadStart(Send));
thread.Start();
}
...
}
static void Send()
{
...
int device_id = _Random.Next(999999);
...
}
}
Run Code Online (Sandbox Code Playgroud)
代码创建指定数量的线程,启动每个线程,并随机分配每个线程device_id
.出于某种原因,创建的前两个线程通常具有相同的线程device_id
.我无法弄清楚为什么会这样.