就算是用delegate的异步调用,也没道理 thread ID 会一样啊。 下面的代码很明确的说明了,当delegate同步调用的时候,才一样,如果是异步调用的话,thread ID肯定是不一样的using System; using System.Linq; using System.Activities; using System.Activities.Statements; using System.Threading;namespace WorkflowConsoleApplication1 { class Program { delegate void Test(); static void Main(string[] args) { //WorkflowInvoker.Invoke(new Workflow1()); Console.WriteLine(Thread.CurrentThread.ManagedThreadId); Program p = new Program(); Test t = new Test(p.ForDelegate); t(); t.BeginInvoke(null, null); } private void ForDelegate() { Console.WriteLine(Thread.CurrentThread.ManagedThreadId); } } }
下面的代码很明确的说明了,当delegate同步调用的时候,才一样,如果是异步调用的话,thread ID肯定是不一样的using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;
using System.Threading;namespace WorkflowConsoleApplication1
{
class Program
{
delegate void Test(); static void Main(string[] args)
{
//WorkflowInvoker.Invoke(new Workflow1()); Console.WriteLine(Thread.CurrentThread.ManagedThreadId); Program p = new Program();
Test t = new Test(p.ForDelegate); t(); t.BeginInvoke(null, null);
} private void ForDelegate()
{
Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
}
}
}
一语惊醒梦中人, 受教了!
这应该是在其内部指定了CPU的编号,或类似这样的行为