Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5939269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:48:15+00:00 2026-05-22T15:48:15+00:00

I’ve got a very simple program written in C#, but the loop never exits

  • 0

I’ve got a very simple program written in C#, but the loop never exits because the times don’t match.

static void Main(string[] args)
{
    while (System.DateTime.Now != new System.DateTime(2011, 05, 23, 22, 17, 0))
    {
    }
    System.Diagnostics.Process.Start(file);   
}

The idea is that when the time ticks over to the specified time, then the given file will be started. However, I’ve tested this program with values which are, for example, just one minute ahead of the current time as reported by Windows, and it won’t start the process. I’ve verified that the Process.Start call is correct. Any suggestions?

Edit: No, this is not an experiment or anything of the sort. It’s because I keep turning off my alarm clocks in my sleep. file is an mp3 file, and I’m going to leave my speakers on, and I’m pretty sure that I don’t possess the capacity to deal with that in my sleep. First ever practical problem I solved with a program. As it possesses a rather specific purpose, I think you’ll agree that the necessity of another solution is, well, limited.

Edit: I didn’t realize that the DateTime type went down to that kind of precision, else I would have spotted this myself. I thought that they were only valid down to the second, and since the loop should run even in debug mode in the IDE many, many times a second, I didn’t see why an exact match would be unreasonable. But, of course, if you’re comparing it down to the hundred nanoseconds, it’s pretty damn unlikely.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:48:15+00:00Added an answer on May 22, 2026 at 3:48 pm

    You should do

    static void Main(string[] args)
    {
        while (System.DateTime.Now < new System.DateTime(2011, 05, 23, 22, 17, 0))
        {
        }
        System.Diagnostics.Process.Start(file);   
    }
    

    Since if you don’t tick on that exact time it isn’t going to ever exit the while

    Edit long explanation of why != most likely won’t work
    So actually you could write the code like this:

    static void Main(string[] args)
    {
        DateTime fireDate = new DateTime(2011, 05, 23, 22, 17, 0);
    
        while (System.DateTime.Now < fireDate)
        {
        }
        System.Diagnostics.Process.Start(file);   
    }
    

    As Ben Voigt pointed out DateTime comparisons looks at the Ticks property on a DateTime DateTime.Ticks which is 1/10,000 of a millisecond.

    Your loop probably doesn’t execute that frequently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a JSP page retrieving data and when single or double quotes are
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.