C ++多线程调度应用程序问题

时间:2016-02-08 14:44:26

标签: c++ multithreading mfc scheduled-tasks

  

背景

我正在维护Windows MFC C ++多线程作业调度应用程序。用户将安排从本地计算机运行的任务。非活动用户将自动将其任务转移给活动用户。

  

问题

有些工作无法运行。它通常是相同的工作,但并不总是相同的工作。有两个工作经常失败。它们具有不同的预期运行时间。它们都被安排在彼此非重叠的时间间隔上运行。

  

创建流程的方法:

作业的位置被输入以下功能:

 int VirtualGridDriver::RunApplicationAsProcessWithExitCode(CString cmdLine)
 {
    PROCESS_INFORMATION processInformation = {0};
    STARTUPINFO startupInfo                = {0};
    startupInfo.cb                         = sizeof(startupInfo);
    int nStrBuffer                         = cmdLine.GetLength() + 50;


   //Create the process
    BOOL result = CreateProcess(NULL, cmdLine.GetBuffer(nStrBuffer), 
                                NULL, NULL, FALSE, 
                                NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, 
                                NULL, NULL, &startupInfo, &processInformation);
    cmdLine.ReleaseBuffer();


    if (!result)
    {
      //CreateProcess() failed
      //Get the error from the system
       LPVOID lpMsgBuf;
       DWORD dw = GetLastError();
       FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 
                     NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);

      //Display the error
       CString strError = (LPTSTR) lpMsgBuf;

      //Free resources created by the system
       LocalFree(lpMsgBuf);

      //We failed.
       return 1;
    }
    else
    {
      //Successfully created the process.  Wait for it to finish.
       WaitForSingleObject( processInformation.hProcess, INFINITE );
       DWORD B;
       GetExitCodeProcess (processInformation.hProcess, &B);

      //Close the handles.
       CloseHandle( processInformation.hProcess );
       CloseHandle( processInformation.hThread );

       int ret = int(B);

      //We succeeded.
       return ret;
    }
 }

失败的作业返回退出代码1.任何人都可以识别可能的问题吗?如果没有,有人可以提供一些我可能会考虑更深入研究的问题吗?这可能是一个多线程问题吗?

0 个答案:

没有答案
相关问题