Timer doesn´t work by Server and Client!
-
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; }
-
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; }
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 ofopen
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
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 ofopen
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
yes it get called! And open takes the correct value! He doesn´t open myTimer_tick!!!!
-
yes it get called! And open takes the correct value! He doesn´t open myTimer_tick!!!!
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
it doesn´t work!
-
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; }
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
-
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
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
-
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
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[^]
-
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[^]
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!
-
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!
PC17 wrote:
but with not!
I assume you meant witg your app NOT. Did you create project as service?
-
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; }
-
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.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
-
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
-
Hi, The code fragment shows that he is using System.Forms.Timer which raises events on the UI thread. Alan.
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
-
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
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!
-
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!
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.
-
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.
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
-
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
-
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.
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?)
-
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?)
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.