我正在尝试在 Microsoft HPC 上测试一个简单设计的代码片段。看起来这项工作没有完成所有代码。我的测试方法可能是错误的。我只是打印一些检查点。这是代码:
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
class S
{
static void Main()
{
pcount = Environment.ProcessorCount;
Console.WriteLine("Proc count = " + pcount);
ThreadPool.SetMinThreads(4, -1);
ThreadPool.SetMaxThreads(4, -1);
// System.Threading.Thread.Sleep(20000);
Console.WriteLine("check point 0 ");
t1 = new Task(A, 1);
t2 = new Task(A, 2);
t3 = new Task(A, 3);
t4 = new Task(A, 4);
Console.WriteLine("Starting t1 " + t1.Id.ToString());
t1.Start();
Console.WriteLine("Starting t2 " + t2.Id.ToString());
t2.Start();
Console.WriteLine("Starting t3 " + t3.Id.ToString());
t3.Start();
Console.WriteLine("Starting t4 " + t4.Id.ToString());
t4.Start();
// Console.ReadLine();
}
static void A(object o)
{
Console.WriteLine("check point A ");
B(o);
}
static void B(object o)
{
int temp = (int)o;
Console.WriteLine("check point B ");
if (temp == 1)
{
C(o);
}
else
{
F(o);
}
}
static void C(object o)
{
Console.WriteLine("check point C ");
D(o);
}
static void D(object o)
{
int temp = (int)o;
Console.WriteLine("check point D " + temp);
if (temp == 2)
{
F(o);
}
else
{
E(o);
}
}
static void E(object o)
{
Console.WriteLine("check point E ");
}
static void F(object o)
{
Console.WriteLine("check point F ");
G(o);
}
static void G(object o)
{
Console.WriteLine("check point G ");
}
static Task t1, t2, t3, t4;
static int pcount;
}
在作业输出中,直到最后才打印。打印输出在任意点随机结束(在随机函数中)。好的,我明白了,它可能无法打印所有内容,因为执行速度比打印快(可能的解释)。但是,如果我尝试放置断点并尝试通过附加到进程进行调试,它只会命中代码第一部分中的断点。看起来与测试打印输出的范围相同。我如何确保代码运行到最后,以便可以命中任何点的断点?