Example #1
0
File: Form1.cs Project: odalet/misc
        private void TestThree_Click(object sender, EventArgs e)
        {
            //This is the most brutal method, which relies entirely on .Net functionality. When stopping the process, it simply kills
            //it, without giving it any chance to clean up. Note that "ping" command does not display any summary when it is stopped
            //in this fashion.

            EnableButtons(false);

            Process proc = Experiments.StartProgramUsingDotNet(Output, true);

            PID = proc.Id;

            DelayTimer          = new Timer();
            DelayTimer.Interval = 6000;
            DelayTimer.Tick    += (o, args) =>
            {
                DelayTimer.Enabled = false;

                Output.AppendText("Stopping..." + Environment.NewLine);
                Experiments.StopProgramByKillingIt(proc);

                EnableButtons(true);
            };
            DelayTimer.Enabled = true;
        }
Example #2
0
File: Form1.cs Project: odalet/misc
        private void TestOne_Click(object sender, EventArgs e)
        {
            //This method is a mix of .Net and pinvoke. It stops the process by closing its command window, similar to clicking
            //the 'X' button in the upper right corner. This generates a Ctrl-C event to all programs, registered with that
            //console.
            //The downside of this method is that it briefly shows the commend window when starting and when stopping the process.

            EnableButtons(false);

            Process proc         = Experiments.StartProgramUsingDotNet(Output, false);
            IntPtr  windowHandle = Experiments.FindWindowHandleFromProcessObjectWithVisibleWindow(proc);

            Experiments.HideCommandWindowUsingPInvoke(windowHandle);

            PID = proc.Id;

            DelayTimer          = new Timer();
            DelayTimer.Interval = 6000;
            DelayTimer.Tick    += (o, args) =>
            {
                DelayTimer.Enabled = false;

                Output.AppendText("Stopping..." + Environment.NewLine);
                Experiments.ShowCommandWindowUsingPInvoke(windowHandle);
                Experiments.StopProgramUsingProcessObjectWithVisibleMainWindow(proc);

                EnableButtons(true);
            };
            DelayTimer.Enabled = true;
        }
Example #3
0
File: Form1.cs Project: odalet/misc
        private void TestFour_Click(object sender, EventArgs e)
        {
            EnableButtons(false);

            Process proc = Experiments.StartProgramUsingDotNet(Output, true);

            PID = proc.Id;

            DelayTimer          = new Timer();
            DelayTimer.Interval = 6000;
            DelayTimer.Tick    += (o, args) =>
            {
                DelayTimer.Enabled = false;

                Output.AppendText("Stopping..." + Environment.NewLine);

                Experiments.StopProgramByAttachingToItsConsoleAndIssuingCtrlCEvent(proc);

                EnableButtons(true);
            };
            DelayTimer.Enabled = true;
        }
Example #4
0
File: Form1.cs Project: odalet/misc
        private void TestTwo_Click(object sender, EventArgs e)
        {
            EnableButtons(false);

            int    pid          = Experiments.StartProgramWithoutWindowUsingPinvoke(Output);
            IntPtr windowHandle = Experiments.FindWindowHandleFromPid(pid);

            PID = pid;

            DelayTimer          = new Timer();
            DelayTimer.Interval = 6000;
            DelayTimer.Tick    += (o, args) =>
            {
                DelayTimer.Enabled = false;

                Output.AppendText("Stopping..." + Environment.NewLine);
                Experiments.StopProgramWithInvisibleWindowUsingPinvoke(windowHandle);

                EnableButtons(true);
            };
            DelayTimer.Enabled = true;
        }