-
How this works?
I am very new to C# windows programming. Basically, I have the code below
Code:
Watcher.Start();
Console.WriteLine(procName + " is under watch...");
Console.WriteLine("Press Enter to stop watching...");
Console.ReadLine();
Watcher.Stop();
If I remove the console code because I don't want to dispaly that console at all (3 lines of code above), my program just calls the stop right away, if however, I don't remove those lines, my program doesn't call stop.
-
Re: How this works?
Console.ReadLine reads a line of input from the user, so your program is actually waiting to continue until you enter something.
If you remove that line, your program runs and then closes the program.
What is the end result you're trying to achieve?
-
Re: How this works?
To watch a process if it's launched without using the console, and let it run in the background/behind the scene. I have changed the property to windows application from console application, but that still doesn't help and it simply closes my program.
here's the code provided by MS but it uses console.
http://code.msdn.microsoft.com/CSPro...tcher-3b8891a4
-
Re: How this works?
The code you're using will work just fine using a windows application instead of a console application and you won't run into this issue.
-
Re: How this works?
It's still closing the program/exe doesn't remain running as it was with the console application because of that readline. What is my alternative?
-
Re: How this works?
Running it in a windows application causes it to close? Then you're doing something horribly wrong.
If you mean the console application still closes, then you need to do something that keeps the application running.
Depending on how you're getting the process you're waiting for, you could try using the Process.WaitForExit() function.
-
Re: How this works?
Where do you have the code in your WinForms app?