Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;多线程调度应用问题_C++_Multithreading_Mfc_Scheduled Tasks - Fatal编程技术网

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

C++ C++;多线程调度应用问题,c++,multithreading,mfc,scheduled-tasks,C++,Multithreading,Mfc,Scheduled Tasks,背景 我正在维护一个Windows MFC C++多线程作业调度应用程序。用户将安排任务从本地计算机运行。非活动用户将自动将其任务转移给活动用户 问题 有些作业无法运行。通常是相同的工作,但不总是相同的工作。有两份工作经常失败。它们具有不同的预期运行时间。它们都计划在彼此不重叠的时间间隔上运行 创建流程的方法: 作业的位置被输入到以下功能中: int VirtualGridDriver::RunApplicationAsProcessWithExitCode(CString cmdLine)

背景

我正在维护一个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。有人能找出可能的问题吗?如果不是,有人能提供一些我可以考虑深入研究的问题吗?这可能是一个多线程问题吗

“失败的作业返回,退出代码为1”-听起来很合理。关于他们失败的原因,这些工作说明了什么?他们记录了什么?请注意,退出代码1不一定是错误-它是由您正在生成的进程定义的。零表示成功是惯例,而不是要求。您确定非零退出代码不是这些作业的正常行为吗?我们看不到可能失败的代码。如果不知道哪个进程返回了进程退出代码,以及特定进程如何发出错误信号,那么进程退出代码就毫无意义。除了调用
GetLastError
太晚,以及调用
ReleaseBuffer
时截断
cmdLine
之外,您发布的代码没有问题。