Results 1 to 7 of 7

Thread: How this works?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    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.

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    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

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    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?

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How this works?

    Where do you have the code in your WinForms app?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width