Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3046

Timer function in multithreading

$
0
0
Hi,

I create a new process from parent process.

Now I need to print the process info on the child process, every 5 mins.

Im thinking of using the windows timer functionality with the call back. Is this ok, to call from the parent process, in the structure below. Ive not compiled the following is just pseudocode

Code:


void CALLBACK ResourceUtilLogFunction(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime)
{
        printf("Hello\n");
}

int main ()
{
        STARTUPINFO si = {};
        si.cb = sizeof si;

        PROCESS_INFORMATION pi = {};
        const TCHAR* target = _T("C:\\Windows\\WinSxS\\wow64_microsoft-windows-calc_31bf3856ad364e35_10.0.19041.1_none_6a03b910ee7a4073\\calc.exe");

        if ( !CreateProcess(target, 0, 0, FALSE, 0, 0, 0, 0, &si, &pi) )
        {
                cerr << "CreateProcess failed (" << GetLastError() << ").\n";
        }
        else
        {
                FILETIME ftime, fsys, fuser;


                SetTimer(NULL, 0, 1000 * 3, (TIMERPROC)& ResourceUtilLogFunction);

                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
        }

        cin.sync();
        cin.ignore();

        return 0;
}


Viewing all articles
Browse latest Browse all 3046

Trending Articles