Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Need to time stamp the last time a file was considered good. [modified]

Need to time stamp the last time a file was considered good. [modified]

Scheduled Pinned Locked Moved C#
performancehelpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lecutus1
    wrote on last edited by
    #1

    Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:

    public static DateTime last_Time;

    public void Packet_Check(int decision)
    { /* checks for last good info packet. checks from lightest to most sever.
    * if decision = 0, add 1 to pass_counter
    * if decision = 1, pass_counter = 0, good packet and timestamps
    */
    /*
    int pass_marker = 0;// make global
    int pass_counter = 0;// make global
    int first_check = 0; // make global bool used if first pass made
    */
    pass_counter++;
    if (decision == 1)
    {
    stateIndicatorComponent2.StateIndex = 4;
    pass_counter = 0;
    last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
    TRUCK_ID_DISPLAY.BackColor = Color.White;
    Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
    }
    else
    {
    if (pass_counter > 3) //change to yellow
    {
    stateIndicatorComponent2.StateIndex = 3;
    //pass_counter++;
    }

                if (pass\_counter > 7) // red
                {
                    stateIndicatorComponent2.StateIndex = 2;   //red
                    //pass\_counter++;
                    //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold;
                }
                if (pass\_counter > 12) // red with warning message
                {
                    //mess sent to operator
                    Diag\_Box.Text = "lastime is " + last\_Time;
                    //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!";
                    if (light == true)
                    {
                        stateIndicatorComponent2.StateIndex = 3;
    
    D L 3 Replies Last reply
    0
    • L Lecutus1

      Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:

      public static DateTime last_Time;

      public void Packet_Check(int decision)
      { /* checks for last good info packet. checks from lightest to most sever.
      * if decision = 0, add 1 to pass_counter
      * if decision = 1, pass_counter = 0, good packet and timestamps
      */
      /*
      int pass_marker = 0;// make global
      int pass_counter = 0;// make global
      int first_check = 0; // make global bool used if first pass made
      */
      pass_counter++;
      if (decision == 1)
      {
      stateIndicatorComponent2.StateIndex = 4;
      pass_counter = 0;
      last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
      TRUCK_ID_DISPLAY.BackColor = Color.White;
      Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
      }
      else
      {
      if (pass_counter > 3) //change to yellow
      {
      stateIndicatorComponent2.StateIndex = 3;
      //pass_counter++;
      }

                  if (pass\_counter > 7) // red
                  {
                      stateIndicatorComponent2.StateIndex = 2;   //red
                      //pass\_counter++;
                      //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold;
                  }
                  if (pass\_counter > 12) // red with warning message
                  {
                      //mess sent to operator
                      Diag\_Box.Text = "lastime is " + last\_Time;
                      //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!";
                      if (light == true)
                      {
                          stateIndicatorComponent2.StateIndex = 3;
      
      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      DateTime.Now is a static property that will always return a DateTime set to the current system's time.

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
      Why are you using VB6? Do you hate yourself? (Christian Graus)

      L 1 Reply Last reply
      0
      • L Lecutus1

        Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:

        public static DateTime last_Time;

        public void Packet_Check(int decision)
        { /* checks for last good info packet. checks from lightest to most sever.
        * if decision = 0, add 1 to pass_counter
        * if decision = 1, pass_counter = 0, good packet and timestamps
        */
        /*
        int pass_marker = 0;// make global
        int pass_counter = 0;// make global
        int first_check = 0; // make global bool used if first pass made
        */
        pass_counter++;
        if (decision == 1)
        {
        stateIndicatorComponent2.StateIndex = 4;
        pass_counter = 0;
        last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
        TRUCK_ID_DISPLAY.BackColor = Color.White;
        Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
        }
        else
        {
        if (pass_counter > 3) //change to yellow
        {
        stateIndicatorComponent2.StateIndex = 3;
        //pass_counter++;
        }

                    if (pass\_counter > 7) // red
                    {
                        stateIndicatorComponent2.StateIndex = 2;   //red
                        //pass\_counter++;
                        //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold;
                    }
                    if (pass\_counter > 12) // red with warning message
                    {
                        //mess sent to operator
                        Diag\_Box.Text = "lastime is " + last\_Time;
                        //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!";
                        if (light == true)
                        {
                            stateIndicatorComponent2.StateIndex = 3;
        
        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        X|

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        L 1 Reply Last reply
        0
        • L Luc Pattyn

          X|

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          L Offline
          L Offline
          Lecutus1
          wrote on last edited by
          #4

          Something like this. Reread

          L 1 Reply Last reply
          0
          • D DaveyM69

            DateTime.Now is a static property that will always return a DateTime set to the current system's time.

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
            Why are you using VB6? Do you hate yourself? (Christian Graus)

            L Offline
            L Offline
            Lecutus1
            wrote on last edited by
            #5

            Thanks. One more bit of knowledge in the bucket.

            1 Reply Last reply
            0
            • L Lecutus1

              Something like this. Reread

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              much better. Now I'll read it. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


              1 Reply Last reply
              0
              • L Lecutus1

                Need to time stamp the last time a file was considered good. I was trying to use something like: last_Time = DateTime.Now;. This is used inside a decision block. The problem even if the condition to enter the particular block isn't met, it still updates. So does DateTime.Now execute no matter what? Now for what I really need. I need to timestamp a infopacket/file/situation as to the last time it passed inspection. In other words when was the last good infopacket/file/situation. The following code is what I thought would work:

                public static DateTime last_Time;

                public void Packet_Check(int decision)
                { /* checks for last good info packet. checks from lightest to most sever.
                * if decision = 0, add 1 to pass_counter
                * if decision = 1, pass_counter = 0, good packet and timestamps
                */
                /*
                int pass_marker = 0;// make global
                int pass_counter = 0;// make global
                int first_check = 0; // make global bool used if first pass made
                */
                pass_counter++;
                if (decision == 1)
                {
                stateIndicatorComponent2.StateIndex = 4;
                pass_counter = 0;
                last_Time = DateTime.Now; // <<<<<<<< EXECUTES EVERY PASS, aargh!!!!!!!!!
                TRUCK_ID_DISPLAY.BackColor = Color.White;
                Performance_Log_File(this.Name, Convert.ToString(last_Time)+ " last good packet " + port_in );
                }
                else
                {
                if (pass_counter > 3) //change to yellow
                {
                stateIndicatorComponent2.StateIndex = 3;
                //pass_counter++;
                }

                            if (pass\_counter > 7) // red
                            {
                                stateIndicatorComponent2.StateIndex = 2;   //red
                                //pass\_counter++;
                                //Diag\_Box.Text = " Last Entry -- " + last\_Time + "\\r\\n " + File\_Write\_Hold;
                            }
                            if (pass\_counter > 12) // red with warning message
                            {
                                //mess sent to operator
                                Diag\_Box.Text = "lastime is " + last\_Time;
                                //Diag\_Box.Text = pass\_counter + " " +this.Name + " has failed to recv good info/packetsince " + last\_Time + " check all input!!!!";
                                if (light == true)
                                {
                                    stateIndicatorComponent2.StateIndex = 3;
                
                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Hi, the code shown has only one way to modify last_Time. If you are not satisfied with the value of last_Time, AFAIK there are only two possibilities: 1. Check(1) is called where Check(0) was intended, causing the block with "ast_Time=now" to execute. 2. More Check(1) calls are performed, maybe entirely unrelated to the ones you are looking at, but since last_Time is static, they all share that one variable. Suggestions: 1. don't use static variables unless you really need them; when they just seem the easy way to solve something, they will come back at you later on. A better way would be to make them non-static and instantiate your class once for every independent series of checks you want to perform (you already have to instantiate since Check itself is not static). 2. choose better names for your variables, especially the class members (last_Time) and the method parameters (decision). Also use boolean type if only two values are allowed, use an enum when more than two non-counting values are acceptable. Instead of if(decision==1) ... I would write if (packetOK) ... or if (packetState==PacketState.Good)... :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                L 1 Reply Last reply
                0
                • L Luc Pattyn

                  Hi, the code shown has only one way to modify last_Time. If you are not satisfied with the value of last_Time, AFAIK there are only two possibilities: 1. Check(1) is called where Check(0) was intended, causing the block with "ast_Time=now" to execute. 2. More Check(1) calls are performed, maybe entirely unrelated to the ones you are looking at, but since last_Time is static, they all share that one variable. Suggestions: 1. don't use static variables unless you really need them; when they just seem the easy way to solve something, they will come back at you later on. A better way would be to make them non-static and instantiate your class once for every independent series of checks you want to perform (you already have to instantiate since Check itself is not static). 2. choose better names for your variables, especially the class members (last_Time) and the method parameters (decision). Also use boolean type if only two values are allowed, use an enum when more than two non-counting values are acceptable. Instead of if(decision==1) ... I would write if (packetOK) ... or if (packetState==PacketState.Good)... :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                  L Offline
                  L Offline
                  Lecutus1
                  wrote on last edited by
                  #8

                  Funny thing you should say about the static last_time. That's exactly what I did. Take off the static and it worked just as planned. Thanks for the second confirmation. ;P That's why I like this place Later!!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups