Freezing after many repeats of CreateProcess

From: Nail Kashapov (nail_at_xiag.ch)
Date: 09/15/04


Date: 14 Sep 2004 22:55:12 -0700

Hello All

I found that WIN32 CreateProcess() isn't stable.
I wrote two small applications. One app (the main) creates another one
many times. The created app is just an empty WinCE console
application.
And this creating completly freezes the device.

There are how the code in the main app looks like:

In the form I have "start" button and a counter:
==================================================================
private void startbutton_Click(object sender, System.EventArgs e)
{
        Background bg = new Background(this);
        bgthread = new Thread(new ThreadStart(bg.Start));
        bgthread.Start();
        startbutton.Enabled = false;
}

public void IncrementCounter()
{
        this.Invoke(new EventHandler(this.incrcounter));
}

private void incrcounter(object sender, EventArgs a)
{
        counter++;
        this.label1.Text = counter.ToString();
}
==================================================================

In Background class:

==================================================================
public void Start()
{
        while (true)
        {
                form.IncrementCounter();
                CreateProcessWaitWin32(
                "\\Program Files\\test\\dummy.exe", "", 30000);
        }
}

public static void CreateProcessWaitWin32(String imageName, String
cmdLine, int ms)
{
        ProcessInfo pi;
        int res;
        res = CreateProcessWin32(imageName, cmdLine, out pi);
        res = WaitForSingleObject(pi.hProcess, ms); /// !!!it crashes here
after many cycles!!!
        res = CloseHandle(pi.hThread);
        res = CloseHandle(pi.hProcess);
}

private static Int32 CreateProcessWin32(
        String imageName, String cmdLine, out ProcessInfo pi)
{
        pi = new ProcessInfo();

        return CreateProcess(
                imageName, cmdLine, IntPtr.Zero, IntPtr.Zero, 0,
                0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pi);
        System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default;
}
==================================================================

It crashes when the counter is about 1700-1800. I added logging and
found that it crashes on WaitForSingleObject. Last unsuccessfull cycle
doesn't even create the slave process

Had anyone such problem?

Regards
Nail