如何在没有定时器的情况下用C#制作数字时钟 [英] How to make digital clock in C# without timer

查看:97
本文介绍了如何在没有定时器的情况下用C#制作数字时钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,你好,我希望你会好起来我的问题是有什么方法可以在没有计时器的情况下在C#中制作数字时钟,因为当我使用计时器,所以我的应用程序工作非常慢我想显示系统日期和时间无论如何,我的应用程序没有计时器,所以请帮助我怎么做呢

谢谢



我尝试过:



label2.text = system.datetime.now.tostring();

Hey Guys, How are you i hope you will be fine well my question is there any way to make digital clock in C# without timer because when I use timer so my application working very slow I want to show system date and time in my application without timer is there anyway so please help me how can I do it
Thanks

What I have tried:

label2.text = system.datetime.now.tostring();

推荐答案

嗯,是。但是,Timer是最简单的方法。如果您的代码是慢,不使用Timer也不会修复任何问题。问题不在于您的计时器,而在您的代码中还有其他内容。



首先分析代码以查看瓶颈所在。
Well, yes. But, a Timer is the easiest way to go. If you code is "slow", not using a Timer isn't going to fix anything. The problem isn't with your Timer but with something else in your code.

Start with profiling your code to see where the bottlenecks are.


以下是适合您的答案:数字时钟程序在c#! [ ^ ]

Here is an answer that will suit you: a digital clock program in c# ![^]
Quote:

一个提示:使用线程,而不是计时器,在线程体也使用System.DateTime。即使使用计时器,也总是从这个结构中抽出时间,从不依赖计时器的计时。 (但是避免使用计时器,一般来说,线程更容易,更安全,更正确;使线程主体循环调用System.Threading.Thread.Sleep,其休眠时间少于一秒。

One hint: use thread, not a timer and, in the thread body also use System.DateTime. Even with timer, always take time from this structure, never rely on timer's timing. (But avoid a timer, a thread is much easier, safer and more correct, in general; make thread body a cycle calling System.Threading.Thread.Sleep with the sleep time less then a second.


这篇关于如何在没有定时器的情况下用C#制作数字时钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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