private delegate void Runner(); //A delegate, but this attempt didn't work
public void Run()
{
Stager.InstructionsMemory = InstructionsTextBox.Text.Split('\n');
Stager.InintializeLists();
InstructionThread = new Thread[Stager.InstructionsMemory.Length];
PipelineInitializor();
BlockingCollection<Func<object>>[] tasks = new BlockingCollection<Func<object>>[Stager.InstructionsMemory.Length];
PCounterLabelUpdate up = new PCounterLabelUpdate(PCounterLabelUpdater);
MemoryUpdater MemUp = new MemoryUpdater(UpdateMemoryLists);
ButtonControl del = new ButtonControl(ButtonController);
ExecuteBtn.Invoke(del, new bool[] { false, true });
Cycle = 0;
for (APCounter = 0; APCounter < Stager.InstructionsMemory.Length; APCounter++)
{
int i1 = APCounter;
int i = APCounter; //Local Copy of Counter
tasks[i] = new BlockingCollection<Func<object>>();
tasks[i].Add(() => Fetch(i1));
tasks[i].Add(() => Decode(i1));
tasks[i].Add(() => ALURes(i1));
tasks[i].Add(() => Memory(i1));
tasks[i].Add(() => WriteB(i1));
InstructionThread[i] = new Thread(() => Worker(i1, tasks[i1]));
InstructionThread[i1].Start(); //Start a Thread
CycleLbl.Invoke(up); // Update GUI Control
this.Invoke(MemUp); // UPdate GUI
_wait.WaitOne(); //Wait
}
ExecuteBtn.Invoke(del, new bool[] { true, false });
}
GUI 完全冻结,不允许我调用 set 方法。
上面的函数是一个线程启动器,我想午餐一定数量的线程,但我想根据一个条件延迟午餐。我使用 for 循环和 _wait.WaitOne();
什么叫跑?一个按钮控制
它卡在哪条线上?_wait.WaitOne()
什么是等待?自动复位事件
为什么是在第一个线程的午餐之后?我想控制启动线程组,让他们完成工作(“使用业务逻辑”),然后午餐更多线程。