what is the max amount of time that a timer can have in its interval in .NET?
Printable View
what is the max amount of time that a timer can have in its interval in .NET?
It accepts Int32 type which means :
it shouldn't exceed this range (2147483647)
hmm that long? are u sure? i remember that in vb6 timers interval was a long value but even there it had a limit inferior to long's value limit i think..or not?!
lol , timers for not more that 1hour at most ! What the hell are you ganna profit from so ??;)
hmm well... i have an app that will try to connect to another app over a network, in case it doest make it he will try in X time that will be defined by the client, and in the most cases should be something like 30min to 2h..thats why i made that question lol
Why you don't go for threading since it's most suitable for such environement !!
threading? i want it to connect from X time to X time it has nothing to do with threading lol
edit: or not?
lol , no need buddy , connection obj has timeout method that calculates the connection availability. ;)
AHHH GOOD IDEIA let me check it
One more thing about threading I forgot to mention is : it has pause and resuem methods which is much more efficient than timers .
well actually i am using a third-party class dll and it doesnt seem to have the connection-timeout thing...and why should i use threading? i really dont get it..i have the ideia that putting this app with more threads will just turn it to more complex with no reason..maybe i should use gettickcount(or time i dont remember exactly) to do that?
otherwise using threads what was ur idea? create a thread and then stop it and resume it?
It's not complex nor hard to manage . I posted a sample , see how simple it works !!
Read more about threading here...
Sleep method , can sleep for seconds , minutes , even days plus it accepts timespan .
You can give your threads high priority to be executed immediately after system threads . It can be suspended (just like system hibernation) . It's really really boosts your program performance !
Hope that helps !
i dont get it. i have a thread1 that calls the CONNECT() sub.
the sub tries to connect but cant connect..then how would it be able to wait the x time? notice how the connect() is about to finish because it has no more code left..and i dont want to make a recursive call to the function itself because that would suck
ok now i think i understood what u mean..the connect() has a loop inside it and in the finish of the loop body has a thread.sleep()
Sleep is used only if you're going to run that thread again , rather you can use Abort method (after successful connection).
wow did it although i had to do that with recursion to the own function because the only way to know when the connection failed is thru catching the exception:
code(in C#):
Code:private void Connect(object sender, System.EventArgs e) {
Thread connectThread = new Thread(new ThreadStart(Connect2));
connectThread.Name = "ConnectThread";
connectThread.Start();
}
private void Connect2() {
try {
if (button1.Text == CONNECT) {
l1.Write("connecting to the other computer...", true, true);
Client.Connect(ip.Text, int.Parse(port.Text));
button1.Text = DISCONNECT;
button1.Enabled = false;
}
else {
Client.Close(false);
l1.Write("connection stoped by user", true, true);
button1.Text = CONNECT;
}
}
catch (Exception err) {
l1.Error(err.Message);
button1.Enabled = true;
Thread.Sleep((int)numericUpDown1.Value * 1000);
if (checkBox3.Checked) {
this.Connect2();
}
}
}
I can't understand the text between quotations !!!!;)
edited them
Hmm, it looks different than the regular connection objs we use in .NET . Why don't you use SQL or OLEDB objs . They have more options like (timeout , connectionstate, ... etc ) , they return wheather the conntions is successful or failed?
hmm i dont undestand..this is socket connection!
Oh yeah , I though you're connection to a database !lol