我试图通过将每个过程(等级)放在一个单独的路口来模拟分配的算法,以便它们成为真正的孤立过程。 这些进程应能相互沟通。
我试图做些什么,可以通过这一法典来证明:
public class Process
{
public void Run()
{
Console.WriteLine("Run called from thread {0}", Thread.CurrentThread.ManagedThreadId);
}
public void Fnc()
{
Console.WriteLine("Fnc called from thread {0}", Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(1000);
}
}
class Program
{
static void Main()
{
Console.WriteLine("Main is running in thread {0}", Thread.CurrentThread.ManagedThreadId);
Process p1 = new Process();
var t1 = new Thread(p1.Run);
t1.Start();
// This should call Fnc() in t1 Thread. It should also return immediatelly not waiting for method Fnc() to finish.
p1.Fnc();
Console.ReadLine();
}
}
I am getting this output:
Main is running in thread 9
Run called from thread 10
Fnc called from thread 9
我想得到这样的东西:
Main is running in thread 9
Run called from thread 10
Fnc called from thread 10
能否实现这种功能?
Thank you!