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. Timer doesn´t work by Server and Client!

Timer doesn´t work by Server and Client!

Scheduled Pinned Locked Moved C#
sysadmin
20 Posts 4 Posters 21 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.
  • N Offline
    N Offline
    nhqlbaislwfiikqraqnm
    wrote on last edited by
    #1

    Hello! Everthing works, but he don´t open myTimer_Tick!!! open takes the value from the textbox, then * 1000 = 5sec! public Form1() { InitializeComponent(); } void myTimer_Tick(object sender, EventArgs e) { System.Diagnostics.Process.Start("winword"); } /*static*/ void Listen() { while (true) { try { data = new byte[1024]; received = networkStream.Read(data, 0, data.Length); if (received == 0) break; string get = Encoding.ASCII.GetString(data, 0, received); var send = get.ToByteArray(); //Console.WriteLine("Received from TCP Client: " + get); networkStream.Write(send, 0, send.Length); if (get.Contains("open_ever_x_sec")) { string[] get_Split2 = get.Split('~'); int open = Convert.ToInt32(get_Split2[1]); timer1.Tick += new EventHandler(myTimer_Tick); timer1.Interval = open * 1000; // Millisekunden timer1.Enabled = true; }

    X S A 3 Replies Last reply
    0
    • N nhqlbaislwfiikqraqnm

      Hello! Everthing works, but he don´t open myTimer_Tick!!! open takes the value from the textbox, then * 1000 = 5sec! public Form1() { InitializeComponent(); } void myTimer_Tick(object sender, EventArgs e) { System.Diagnostics.Process.Start("winword"); } /*static*/ void Listen() { while (true) { try { data = new byte[1024]; received = networkStream.Read(data, 0, data.Length); if (received == 0) break; string get = Encoding.ASCII.GetString(data, 0, received); var send = get.ToByteArray(); //Console.WriteLine("Received from TCP Client: " + get); networkStream.Write(send, 0, send.Length); if (get.Contains("open_ever_x_sec")) { string[] get_Split2 = get.Split('~'); int open = Convert.ToInt32(get_Split2[1]); timer1.Tick += new EventHandler(myTimer_Tick); timer1.Interval = open * 1000; // Millisekunden timer1.Enabled = true; }

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      are you sure that this condition is true

      if (get.Contains("open_ever_x_sec"))

      put a break point in there and see if it get called or not. If it does then check that is Tick event attached with timer1 and what is the value of open

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

      ----------------------------------------------- 128 bit encrypted signature, crack if you can

      N 1 Reply Last reply
      0
      • X Xmen Real

        are you sure that this condition is true

        if (get.Contains("open_ever_x_sec"))

        put a break point in there and see if it get called or not. If it does then check that is Tick event attached with timer1 and what is the value of open

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

        ----------------------------------------------- 128 bit encrypted signature, crack if you can

        N Offline
        N Offline
        nhqlbaislwfiikqraqnm
        wrote on last edited by
        #3

        yes it get called! And open takes the correct value! He doesn´t open myTimer_tick!!!!

        X 1 Reply Last reply
        0
        • N nhqlbaislwfiikqraqnm

          yes it get called! And open takes the correct value! He doesn´t open myTimer_tick!!!!

          X Offline
          X Offline
          Xmen Real
          wrote on last edited by
          #4

          It suppose to get called, btw write following line after InitializeComponents()

          timer1.Tick += new EventHandler(myTimer_Tick);

          and remove from while loop.

          TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

          ----------------------------------------------- 128 bit encrypted signature, crack if you can

          N 1 Reply Last reply
          0
          • X Xmen Real

            It suppose to get called, btw write following line after InitializeComponents()

            timer1.Tick += new EventHandler(myTimer_Tick);

            and remove from while loop.

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

            ----------------------------------------------- 128 bit encrypted signature, crack if you can

            N Offline
            N Offline
            nhqlbaislwfiikqraqnm
            wrote on last edited by
            #5

            it doesn´t work!

            1 Reply Last reply
            0
            • N nhqlbaislwfiikqraqnm

              Hello! Everthing works, but he don´t open myTimer_Tick!!! open takes the value from the textbox, then * 1000 = 5sec! public Form1() { InitializeComponent(); } void myTimer_Tick(object sender, EventArgs e) { System.Diagnostics.Process.Start("winword"); } /*static*/ void Listen() { while (true) { try { data = new byte[1024]; received = networkStream.Read(data, 0, data.Length); if (received == 0) break; string get = Encoding.ASCII.GetString(data, 0, received); var send = get.ToByteArray(); //Console.WriteLine("Received from TCP Client: " + get); networkStream.Write(send, 0, send.Length); if (get.Contains("open_ever_x_sec")) { string[] get_Split2 = get.Split('~'); int open = Convert.ToInt32(get_Split2[1]); timer1.Tick += new EventHandler(myTimer_Tick); timer1.Interval = open * 1000; // Millisekunden timer1.Enabled = true; }

              S Offline
              S Offline
              Saksida Bojan
              wrote on last edited by
              #6

              try adding timer1.Start(); check if VS didn't already assign event handler If that doesn't work, try this:

              Timer time1 = nre Timer();
              time1.Tick += new EventHandler(myTimer_Tick);
              time1.Interval = 2 * 1000;
              time1.Enabled = true;

              modified on Saturday, August 22, 2009 6:38 AM

              N 1 Reply Last reply
              0
              • S Saksida Bojan

                try adding timer1.Start(); check if VS didn't already assign event handler If that doesn't work, try this:

                Timer time1 = nre Timer();
                time1.Tick += new EventHandler(myTimer_Tick);
                time1.Interval = 2 * 1000;
                time1.Enabled = true;

                modified on Saturday, August 22, 2009 6:38 AM

                N Offline
                N Offline
                nhqlbaislwfiikqraqnm
                wrote on last edited by
                #7

                doesn´t work! nre Timer ;awaited!!! I have tried the code in a new windows form application i have put this code into button click: timer1.Tick += new EventHandler(myTimer_Tick); timer1.Interval = 10000; // Millisekunden timer1.Enabled = true; and that above the Button_klick void myTimer_Tick(object sender, EventArgs e) { mciSendString("set CDAudio door open", null, 127, (IntPtr)0); } And it doesn´t work! Can somebody try it in a new windows form application and when it works can he send me the full code!!! Please

                S 1 Reply Last reply
                0
                • N nhqlbaislwfiikqraqnm

                  doesn´t work! nre Timer ;awaited!!! I have tried the code in a new windows form application i have put this code into button click: timer1.Tick += new EventHandler(myTimer_Tick); timer1.Interval = 10000; // Millisekunden timer1.Enabled = true; and that above the Button_klick void myTimer_Tick(object sender, EventArgs e) { mciSendString("set CDAudio door open", null, 127, (IntPtr)0); } And it doesn´t work! Can somebody try it in a new windows form application and when it works can he send me the full code!!! Please

                  S Offline
                  S Offline
                  Saksida Bojan
                  wrote on last edited by
                  #8

                  void myTimer_Tick(object sender, EventArgs e)
                  {
                  MessageBox.Show("1");
                  }
                  void listen()
                  {
                  Timer time1 = new Timer();
                  time1.Tick += new EventHandler(myTimer_Tick);
                  time1.Interval = 1 * 1000;
                  time1.Enabled = true;
                  time1.Start();
                  }

                  I Have tried this at windows form app and it worked. However i coudn't do with console app. I noticed that console app timer doesn't work, so i found alternative solution: http://www.mycsharpcorner.com/post.aspx?postid=31[^]

                  N 1 Reply Last reply
                  0
                  • S Saksida Bojan

                    void myTimer_Tick(object sender, EventArgs e)
                    {
                    MessageBox.Show("1");
                    }
                    void listen()
                    {
                    Timer time1 = new Timer();
                    time1.Tick += new EventHandler(myTimer_Tick);
                    time1.Interval = 1 * 1000;
                    time1.Enabled = true;
                    time1.Start();
                    }

                    I Have tried this at windows form app and it worked. However i coudn't do with console app. I noticed that console app timer doesn't work, so i found alternative solution: http://www.mycsharpcorner.com/post.aspx?postid=31[^]

                    N Offline
                    N Offline
                    nhqlbaislwfiikqraqnm
                    wrote on last edited by
                    #9

                    Thanks, alright your code works in a new Windows Form Application but with not! I have tried nearly everthing but it doesn´t work!!! this code also works, but not by Server and Client: for(int i =0;i<int.MaxValue;i++) { System.Diagnostics.Process.Create('winword'); // Word System.Threading.Thread.Sleep(10000); // 10 Seconds } I don´t why but it doesn´t work!!!:confused::confused::confused::confused::confused: Thank you at all!

                    S 1 Reply Last reply
                    0
                    • N nhqlbaislwfiikqraqnm

                      Thanks, alright your code works in a new Windows Form Application but with not! I have tried nearly everthing but it doesn´t work!!! this code also works, but not by Server and Client: for(int i =0;i<int.MaxValue;i++) { System.Diagnostics.Process.Create('winword'); // Word System.Threading.Thread.Sleep(10000); // 10 Seconds } I don´t why but it doesn´t work!!!:confused::confused::confused::confused::confused: Thank you at all!

                      S Offline
                      S Offline
                      Saksida Bojan
                      wrote on last edited by
                      #10

                      PC17 wrote:

                      but with not!

                      I assume you meant witg your app NOT. Did you create project as service?

                      1 Reply Last reply
                      0
                      • N nhqlbaislwfiikqraqnm

                        Hello! Everthing works, but he don´t open myTimer_Tick!!! open takes the value from the textbox, then * 1000 = 5sec! public Form1() { InitializeComponent(); } void myTimer_Tick(object sender, EventArgs e) { System.Diagnostics.Process.Start("winword"); } /*static*/ void Listen() { while (true) { try { data = new byte[1024]; received = networkStream.Read(data, 0, data.Length); if (received == 0) break; string get = Encoding.ASCII.GetString(data, 0, received); var send = get.ToByteArray(); //Console.WriteLine("Received from TCP Client: " + get); networkStream.Write(send, 0, send.Length); if (get.Contains("open_ever_x_sec")) { string[] get_Split2 = get.Split('~'); int open = Convert.ToInt32(get_Split2[1]); timer1.Tick += new EventHandler(myTimer_Tick); timer1.Interval = open * 1000; // Millisekunden timer1.Enabled = true; }

                        A Offline
                        A Offline
                        Alan N
                        wrote on last edited by
                        #11

                        Hi, It works but it doesn't! I have questions about the Listen method. Does it block at received = networkStream.Read(data, 0, data.Length); until data arrives? What happens next, that is, does it loop around and block again waiting for more data? Alan.

                        S 1 Reply Last reply
                        0
                        • A Alan N

                          Hi, It works but it doesn't! I have questions about the Listen method. Does it block at received = networkStream.Read(data, 0, data.Length); until data arrives? What happens next, that is, does it loop around and block again waiting for more data? Alan.

                          S Offline
                          S Offline
                          Saksida Bojan
                          wrote on last edited by
                          #12

                          Timer works in diffrent Thread, as soon Timer.Enabled set to true, it will send event every time an event Ticked and it doesn't matter how occupied is the main thread

                          A 1 Reply Last reply
                          0
                          • S Saksida Bojan

                            Timer works in diffrent Thread, as soon Timer.Enabled set to true, it will send event every time an event Ticked and it doesn't matter how occupied is the main thread

                            A Offline
                            A Offline
                            Alan N
                            wrote on last edited by
                            #13

                            Hi, The code fragment shows that he is using System.Forms.Timer which raises events on the UI thread. Alan.

                            S 1 Reply Last reply
                            0
                            • A Alan N

                              Hi, The code fragment shows that he is using System.Forms.Timer which raises events on the UI thread. Alan.

                              S Offline
                              S Offline
                              Saksida Bojan
                              wrote on last edited by
                              #14

                              I Think you are on to something.

                              Timer time1 = new Timer();
                              time1.Tick += new EventHandler(myTimer_Tick);
                              time1.Interval = 1 * 1000;
                              time1.Enabled = true;
                              time1.Start();
                              while (true)
                              {
                              // do nothing
                              }

                              This above code doesn't fire anything, so i think he needs to create timer in another class, while that class is created in a diffrent thread using System.Threading

                              N 1 Reply Last reply
                              0
                              • S Saksida Bojan

                                I Think you are on to something.

                                Timer time1 = new Timer();
                                time1.Tick += new EventHandler(myTimer_Tick);
                                time1.Interval = 1 * 1000;
                                time1.Enabled = true;
                                time1.Start();
                                while (true)
                                {
                                // do nothing
                                }

                                This above code doesn't fire anything, so i think he needs to create timer in another class, while that class is created in a diffrent thread using System.Threading

                                N Offline
                                N Offline
                                nhqlbaislwfiikqraqnm
                                wrote on last edited by
                                #15

                                It doesn´t work! I have tired it with a new server and client and it doesn´t work here is the Server and Client Source code with timer: http://ul.to/7xbgwn[^] if by somebody works, please post me!

                                A 1 Reply Last reply
                                0
                                • N nhqlbaislwfiikqraqnm

                                  It doesn´t work! I have tired it with a new server and client and it doesn´t work here is the Server and Client Source code with timer: http://ul.to/7xbgwn[^] if by somebody works, please post me!

                                  A Offline
                                  A Offline
                                  Alan N
                                  wrote on last edited by
                                  #16

                                  Hi, Finally you post code showing the root cause of the problem. The Listen method is running on a secondary thread and the System.Windows.Forms.Timer is designed to operate on the UI thread only. You may 1) Wrap the timer manipulation code in a method and use this.Invoke and a method delegate to force the code to run on the UI thread. OR 2) Change the timer to either System.Threading.Timer or System.Timer. Option 2 would be the cleaner solution. Alan.

                                  N 1 Reply Last reply
                                  0
                                  • A Alan N

                                    Hi, Finally you post code showing the root cause of the problem. The Listen method is running on a secondary thread and the System.Windows.Forms.Timer is designed to operate on the UI thread only. You may 1) Wrap the timer manipulation code in a method and use this.Invoke and a method delegate to force the code to run on the UI thread. OR 2) Change the timer to either System.Threading.Timer or System.Timer. Option 2 would be the cleaner solution. Alan.

                                    N Offline
                                    N Offline
                                    nhqlbaislwfiikqraqnm
                                    wrote on last edited by
                                    #17

                                    I tried the the second solution, but it doesn´t work! Maybe i habe made something wrong can you send me the code how do you mean! Please

                                    A 1 Reply Last reply
                                    0
                                    • N nhqlbaislwfiikqraqnm

                                      I tried the the second solution, but it doesn´t work! Maybe i habe made something wrong can you send me the code how do you mean! Please

                                      A Offline
                                      A Offline
                                      Alan N
                                      wrote on last edited by
                                      #18

                                      Hi, Your most common response to any suggestion is "it doesn't work" without any backup information. Please post a relevant code sample with details of the test you performed and the result of the test. Alan.

                                      N 1 Reply Last reply
                                      0
                                      • A Alan N

                                        Hi, Your most common response to any suggestion is "it doesn't work" without any backup information. Please post a relevant code sample with details of the test you performed and the result of the test. Alan.

                                        N Offline
                                        N Offline
                                        nhqlbaislwfiikqraqnm
                                        wrote on last edited by
                                        #19

                                        i used this code: <code>System.Threading.Timer time1 = new System.Threading.Timer(); time1.Tick += new EventHandler(t1_Tick); time1.Interval = 1 * 1000; time1.Enabled = true; time1.Start(); while (true) { // do nothing }</code> he writes a lot! System.Threading.Timer doesn´t have a construktor That for all that i have made fat: "System.Threading.Timer" contains no definition of "tick", and there was no extension method 'tick' will be found that the first argument of type "System.Threading.Timer" accepted. (Are you missing a using directive or an assembly reference?)

                                        A 1 Reply Last reply
                                        0
                                        • N nhqlbaislwfiikqraqnm

                                          i used this code: <code>System.Threading.Timer time1 = new System.Threading.Timer(); time1.Tick += new EventHandler(t1_Tick); time1.Interval = 1 * 1000; time1.Enabled = true; time1.Start(); while (true) { // do nothing }</code> he writes a lot! System.Threading.Timer doesn´t have a construktor That for all that i have made fat: "System.Threading.Timer" contains no definition of "tick", and there was no extension method 'tick' will be found that the first argument of type "System.Threading.Timer" accepted. (Are you missing a using directive or an assembly reference?)

                                          A Offline
                                          A Offline
                                          Alan N
                                          wrote on last edited by
                                          #20

                                          Hi As you have found, the code is incorrect and will not compile. The error message is telling you that Tick, Interval, Enabled and Start do not exist in the System.Threading.Timer class. It is really up to you to learn how to use the class by reading the documentation. System.Threading.Timer[^] Alan.

                                          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