在C#.net中调用计时器 [英] Call Timer in C#.net

查看:78
本文介绍了在C#.net中调用计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我在C#.net中工作.我在我的项目中使用Timer.请回答我的问题.
Q1)如何在C#.net中将一个Form Timer用于另一个? Q2)有可能吗?请在C#.net中提供一些编码吗?
问候,
Lakshmi narayanan.S

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

推荐答案

1)这不是两个问题.这是一个有需求的问题.


我不建议这样做:当您将表单内部结构暴露给另一种表单时,将使将来的维护变得困难,因为您将两种表单捆绑在一起:您不能在不考虑对另一种表单的影响的情况下更改其中一种.

但是,如果出于某种奇怪的原因,您确实必须这样做,则可以在您的窗体中创建一个公共属性以暴露Timer对象,或者将其传递给第二个窗体中的公共属性.

由于这对我来说听起来像是作业(在那是很糟糕的作业),因此您可以自己编写代码-这并不困难!
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!


1)您不要打电话给a计时器" —计时器会呼叫您.

2)最好避免使用计时器;在大多数情况下,可以用更简单,可靠和安全的线程替换计时器.这里是解释: C#中的计时器线程 [
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


Q1毫无意义.
Q2不是问题,似乎是Q1重复了吗?

尝试发布一些代码并解释您要做什么.
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.


这篇关于在C#.net中调用计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆