嘿所以我正在努力做下面的逻辑。保持子进程在打开数据时打开?
创建父应用程序,创建子进程,有孩子的过程调查数据,将数据发送到父应用程序,
一切都设置很好,当我手动Console.WriteLine在子过程,我收到的罚款工作父应用程序。 问题在于,子进程轮询来自xbox控制器的输入,然后将该信息发送给父应用程序。问题在于,只要满足一定的条件而不是关闭,我可以考虑让子进程保持活动状态的唯一方式就是放在Main中的while循环中。 然而,while循环不允许进程轮询,因为它刚刚停留在循环中。 主要的警告是轮询是通过事件完成的,所以我不能手动轮询。
有关如何保持被动事件类型轮询在保持流程打开的同时工作的任何想法?
下面是设置:
static Battler m_battler = new Battler();
static void Main(string[] args)
{
m_battler = new Battler();
string[] procArgs = (string[])args;
if (procArgs.Length == 0)
{
Console.WriteLine("No Args passed");
Console.Read();
return;
}
parsedArg = procArgs[0].Split('^');
m_battler.NumBattles = Convert.ToInt32(parsedArg[0]);
m_battler有它的控制器,然后使用事件来调用一个函数来解析输入,并将其发送给父应用程序,再没有投票循环的就像m_xboxController.ProcessedDebugOutput + = new XboxController.DebugOutputHandler(Result);
结果分析一切,然后将其发送到父应用程序
private void AddHandler()
{
Console.WriteLine("handler");
m_xboxController = new XboxController();
TestDelegate testDel = new TestDelegate(Result);
m_xboxController.ProcessedDebugOutput += new XboxController.DebugOutputHandler(testDel);
threadInit = false;
}
public void Init(int consoleNum, string activeConsole)
{
ThreadStart ts = new ThreadStart(AddHandler);
outputThread = new Thread(ts);
outputThread.Start();
while (threadInit)
{
continue;
}
}
这里是正在发生的事情
为什么不在单独的线程中运行轮询循环? –
我已经尝试过,但它的所有事件驱动,我不知道如何确切地得到那个工作时使用线程。我会在问题中加入更多信息 – Darthlemi