1. <i id='q9eoQ'><tr id='q9eoQ'><dt id='q9eoQ'><q id='q9eoQ'><span id='q9eoQ'><b id='q9eoQ'><form id='q9eoQ'><ins id='q9eoQ'></ins><ul id='q9eoQ'></ul><sub id='q9eoQ'></sub></form><legend id='q9eoQ'></legend><bdo id='q9eoQ'><pre id='q9eoQ'><center id='q9eoQ'></center></pre></bdo></b><th id='q9eoQ'></th></span></q></dt></tr></i><div id='q9eoQ'><tfoot id='q9eoQ'></tfoot><dl id='q9eoQ'><fieldset id='q9eoQ'></fieldset></dl></div>
      • <bdo id='q9eoQ'></bdo><ul id='q9eoQ'></ul>
      <legend id='q9eoQ'><style id='q9eoQ'><dir id='q9eoQ'><q id='q9eoQ'></q></dir></style></legend>
      <tfoot id='q9eoQ'></tfoot>

    2. <small id='q9eoQ'></small><noframes id='q9eoQ'>

      如何将计时器添加到 C# 控制台应用程序

      时间:2023-08-26

          <bdo id='nMXYA'></bdo><ul id='nMXYA'></ul>
          • <legend id='nMXYA'><style id='nMXYA'><dir id='nMXYA'><q id='nMXYA'></q></dir></style></legend>

            <small id='nMXYA'></small><noframes id='nMXYA'>

          • <i id='nMXYA'><tr id='nMXYA'><dt id='nMXYA'><q id='nMXYA'><span id='nMXYA'><b id='nMXYA'><form id='nMXYA'><ins id='nMXYA'></ins><ul id='nMXYA'></ul><sub id='nMXYA'></sub></form><legend id='nMXYA'></legend><bdo id='nMXYA'><pre id='nMXYA'><center id='nMXYA'></center></pre></bdo></b><th id='nMXYA'></th></span></q></dt></tr></i><div id='nMXYA'><tfoot id='nMXYA'></tfoot><dl id='nMXYA'><fieldset id='nMXYA'></fieldset></dl></div>
          • <tfoot id='nMXYA'></tfoot>
              <tbody id='nMXYA'></tbody>

              1. 本文介绍了如何将计时器添加到 C# 控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                就是这样 - 如何将计时器添加到 C# 控制台应用程序?如果您能提供一些示例编码,那就太好了.

                Just this - How do you add a timer to a C# console application? It would be great if you could supply some example coding.

                推荐答案

                这很好,但是为了模拟一些时间流逝,我们需要运行一个需要一些时间的命令,这在第二个示例中非常清楚.

                That's very nice, however in order to simulate some time passing we need to run a command that takes some time and that's very clear in second example.

                但是,使用 for 循环来执行某些功能的方式永远会占用大量设备资源,而我们可以使用垃圾收集器来执行类似的操作.

                However, the style of using a for loop to do some functionality forever takes a lot of device resources and instead we can use the Garbage Collector to do some thing like that.

                我们可以在同一本书 CLR Via C# Third Ed 的代码中看到这种修改.

                We can see this modification in the code from the same book CLR Via C# Third Ed.

                using System;
                using System.Threading;
                
                public static class Program 
                {
                   private Timer _timer = null;
                   public static void Main() 
                   {
                      // Create a Timer object that knows to call our TimerCallback
                      // method once every 2000 milliseconds.
                      _timer = new Timer(TimerCallback, null, 0, 2000);
                      // Wait for the user to hit <Enter>
                      Console.ReadLine();
                   }
                
                   private static void TimerCallback(Object o) 
                   {
                      // Display the date/time when this method got called.
                      Console.WriteLine("In TimerCallback: " + DateTime.Now);
                   }
                }
                

                这篇关于如何将计时器添加到 C# 控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:显示/隐藏 C# 控制台应用程序的控制台窗口 下一篇:Console.Read() 和 Console.ReadLine() 之间的区别?

                相关文章

                最新文章

                <small id='z3hHS'></small><noframes id='z3hHS'>

                <legend id='z3hHS'><style id='z3hHS'><dir id='z3hHS'><q id='z3hHS'></q></dir></style></legend>
                  <bdo id='z3hHS'></bdo><ul id='z3hHS'></ul>
              2. <i id='z3hHS'><tr id='z3hHS'><dt id='z3hHS'><q id='z3hHS'><span id='z3hHS'><b id='z3hHS'><form id='z3hHS'><ins id='z3hHS'></ins><ul id='z3hHS'></ul><sub id='z3hHS'></sub></form><legend id='z3hHS'></legend><bdo id='z3hHS'><pre id='z3hHS'><center id='z3hHS'></center></pre></bdo></b><th id='z3hHS'></th></span></q></dt></tr></i><div id='z3hHS'><tfoot id='z3hHS'></tfoot><dl id='z3hHS'><fieldset id='z3hHS'></fieldset></dl></div>

                  1. <tfoot id='z3hHS'></tfoot>