Time calculation in windows application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Limno
    New Member
    • Apr 2008
    • 92

    Time calculation in windows application

    Hai,

    My windows application in C#.net should display time which
    is also running like System time. And i hv to check time as morning 10.00AM to next day morning 10.00AM. if this happen it should clear the grid data and display new grid without value. How can i Do this?

    Thanks in advance
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Read up on DateTime object.

    DateTime.Now

    DateTime.Now.To String("hh:mm tt");

    Play a bit with that and come back with the code you create if you are still having issues.

    Comment

    • Limno
      New Member
      • Apr 2008
      • 92

      #3
      Originally posted by tlhintoq
      Read up on DateTime object.

      DateTime.Now

      DateTime.Now.To String("hh:mm tt");

      Play a bit with that and come back with the code you create if you are still having issues.


      Thanks for Replying me,

      I hv display system time in textbox with the code

      Code:
      private void timer1_Tick(object sender, EventArgs e)
              {
                  textBox1.Text = DateTime.Now.ToString("h:mm:ss tt");
              }
      but i dont knw how to trigger event on specific time in c#.net

      let say if time reaches 10.00AM it trigger tht event as refresh tht grid

      reply me
      Last edited by tlhintoq; Jun 23 '09, 11:44 AM. Reason: [CODE] ... your code here ... [/CODE] tags added

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        but i dont knw how to trigger event on specific time in c#.net
        There isn't a pre-built event for that.
        You will have to write your own.
        Basically a set of 'if' conditions that you can put inside the Tick event is a good basic start. This will get you started for concept, but you'll need to beef it up.

        Code:
        If (DateTime.Now.Hours == AlarmTime.Hours)
        {
           if (DateTime.Now.Minutes == AlarmTime.Minutes)
           {
              if (!RanToday) RaiseTodaysAlarmEvent();
           }
        }

        Comment

        • Limno
          New Member
          • Apr 2008
          • 92

          #5
          Originally posted by tlhintoq
          There isn't a pre-built event for that.
          You will have to write your own.
          Basically a set of 'if' conditions that you can put inside the Tick event is a good basic start. This will get you started for concept, but you'll need to beef it up.

          Code:
          If (DateTime.Now.Hours == AlarmTime.Hours)
          {
             if (DateTime.Now.Minutes == AlarmTime.Minutes)
             {
                if (!RanToday) RaiseTodaysAlarmEvent();
             }
          }

          Can u explain me more. What's this code mean? i need to display data in datagridview with the sql query, it should check morning 10AM to next day 10AM. it displays the data in datagridview with this query and next day it should display new page. need to check with time and date.

          Thanks in Advance

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            So you're saying that you have a program that will be constantly running, and needs to have something happen every 24 hours?

            You could use a timer and set the interval to 24 hours (86,400,000 ms). Subscribe to the timer's tick event and do your update there.

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              Originally posted by insertAlias
              So you're saying that you have a program that will be constantly running, and needs to have something happen every 24 hours?

              You could use a timer and set the interval to 24 hours (86,400,000 ms). Subscribe to the timer's tick event and do your update there.
              The problem with that is that if the something is supposed to happen every day at 10am, but the program is started at 1pm then repeats every 24hours....

              Better to have a settable field for the time, then check to see if now is approximately equal to that time

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                Yeah I forgot about the whole start time thing. There is probably an even better solution, like a refresh button, or closing the app when you are done, and opening it when it's time to use it.

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  Originally posted by insertAlias
                  Yeah I forgot about the whole start time thing. There is probably an even better solution, like a refresh button, or closing the app when you are done, and opening it when it's time to use it.
                  User interaction seems to be contrary to the idea of automated server functions.

                  In my own apps I found it easiest to write a little component that is given a time like an alarm clock. At the appointed time it raises an 'AlarmEvent'. Whichever parts of the main application that are subscribed are welcome to do their thing when the alarm rings. Doesn't mater if its 1 piece, 100 pieces or no pieces, the alarm rings whether someone is listening or not. Much like my beside clock.

                  The alarm clock sits in my toolbar and is available to any program I need it in, just like a TextBox or any other control.

                  Comment

                  • Curtis Rutland
                    Recognized Expert Specialist
                    • Apr 2008
                    • 3264

                    #10
                    Originally posted by tlhintoq
                    User interaction seems to be contrary to the idea of automated server functions.
                    I agree fully, however, the OP mentioned that it would be displaying data in a datagridview, which suggests to me that this isn't really a server app.

                    Comment

                    Working...