Click here to Skip to main content
15,880,854 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Hi friends,
I am working in C#.net. I am using Timer in my Project.So Please answer my questions.
Q1) How can i use One Form Timer to another in C#.net?
Q2) Is it Possible?Please give some coding in C#.net?
Regards,
Lakshmi narayanan.S
Posted
Comments
ambarishtv 8-Jun-11 3:15am    
Please improve your Question
version_2.0 8-Jun-11 4:16am    
not clear...

1) That isn't two questions. It's one question with a demand.


I don't recommend it: when you expose form internals to another form you make future maintenance difficult, because you have tied to two forms together: you cannot change one without considering the effects on the other.

But, if for some strange reason your really must, then create a public property in your form which exposes the Timer object, or pass it to a public property on the second form.

Since this smells like homework to me (and pretty bad homework at that) You can work out the code for yourself - it's not difficult!
 
Share this answer
 
Comments
ambarishtv 8-Jun-11 3:18am    
good points ..
+5
naraayanan 8-Jun-11 4:47am    
Thanks
Sergey Alexandrovich Kryukov 8-Jun-11 13:30pm    
Correct, my 5. See also my answer.
--SA
1) You do not "call a timer" — a timer calls you.

2) Timers should be best avoided; in most cases, a timer can be replaced with much more simple, robust and safe thread. Here is the explanation: Timer Threading in C#[^].

3) There are three types of timer in .NET. System.Windows.Forms.Timer (you probably mean in the question) is the worst one. It's probably designed for very inexperienced developers who do not demand any accuracy. If any timer should be avoided, but this type should be avoided by any means.

4) As to the questions Q1 and Q2, I agree with Cristian.

—SA
 
Share this answer
 
v2
Comments
ambarishtv 8-Jun-11 3:31am    
my 5 :)
Sergey Alexandrovich Kryukov 8-Jun-11 12:21pm    
Thank you, Ambarish.
--SA
thatraja 8-Jun-11 4:43am    
This makes sense, 5!
Sergey Alexandrovich Kryukov 8-Jun-11 12:21pm    
Thank you, Raja.
--SA
naraayanan 8-Jun-11 4:47am    
Thanks
Q1 makes no sense.
Q2 is not a question, it seems to be Q1 repeated ?

Try posting some code and explaining what you want to do.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 3:21am    
I agree, my 5, but there is more to it -- please see my answer.
--SA
naraayanan 8-Jun-11 4:47am    
Thanks
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 3:26am    
That is pretty lame solution, but I vote 4 this time.
Please see my answer and my comments to the answer by Abhinav.
--SA
Abhinav S 8-Jun-11 3:44am    
Yes is a better solution than mine. My 5.
naraayanan 8-Jun-11 4:47am    
Thanks
Keep an object reference to form2 in form1.
Everytime a the timer method executes in form1, call the method you need in form2.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 3:24am    
Would work but violates some isolation principles (please see one of the discussions of form collaboration; I always suggest one form implements appropriate interface and pass only the interface reference to other form(s)). Besides, I hardly believe a timer can not be avoided. I vote 4 this time.
Please see my answer.
--SA
Christian Graus 8-Jun-11 3:43am    
Would work, but if you worked for me, your job would be in danger when I saw the code.
thatraja 8-Jun-11 4:43am    
:D
naraayanan 8-Jun-11 4:47am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900