'Program not exiting properly

I am working on a program that is supposed to run for 3 days checking for pending messages and I want it to skip some of the processing that it does if there are pending messages in the database but I want it to continue to the next day and if there are pending messages on the last day I want the program to exit. The problem is that when I run it in debug mode in VS it starts over from the beginning including the Build process. This is the code that I am using to check for the last day of the run:

intDateCompare = DateTime.Compare(dtDate2, dtDate3);
if (intDateCompare == 0) {
    Console.WriteLine("Finished, press <Enter> to quit");
    strFinished = Console.ReadLine();
    Environment.Exit(1);
}

It does the compare properly and runs the Exit command like expected when I put a breakpoint there but then it starts the Build process again. What am I doing wrong?

Thanks for any suggestions.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source