簡體   English   中英

如何以相反的順序獲得計數?

[英]how to get the count of the in the reverse order?

我如何以相反的順序獲得計數? 現在,我已經顯示了完成計數的數量。但是我也想要剩余的計數數量。 又如何在每天結束時在以下程序中重置計時器並顯示上次執行時間? 有人可以幫我整個程序嗎? 該計划是-

namespace Time_Writer
{
  class Program
  {
    static int count = 1;
    static double seconds;
    private static System.Timers.Timer aTimer;


    static void Main(string[] args)
    {
        ReadCountFromFile();


        aTimer = new System.Timers.Timer();
        aTimer.Elapsed +=new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
        aTimer.Interval = 5000;
        aTimer.Enabled = true;
        Console.WriteLine("Press Enter To Exit The Program\n");
        Console.ReadLine();


        AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);


    }
    private static void ReadCountFromFile()
    {
        try
        {
            if (File.Exists(".\\mynumber.dat"))
            {
                using (var file = File.Open(".\\mynumber.dat", FileMode.Open))
                {
                    byte[] bytes = new byte[4];
                    file.Read(bytes, 0, 4);
                    count = BitConverter.ToInt32(bytes, 0);
                    Console.WriteLine("Limit = 10000");
                    Console.WriteLine("Count  = {0}", count);

                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Problem reading file.");
        }
    }
    static void CurrentDomain_ProcessExit(Object sender, EventArgs e)
    {
        using (var file = File.Open(".\\mynumber.dat", FileMode.OpenOrCreate))
        {
            var buffer = BitConverter.GetBytes(count);
            file.Write(buffer, 0, buffer.Length);
        }
    }
    private static void aTimer_Elapsed(object source, ElapsedEventArgs e)
    {
        Console.WriteLine("Name is Yap {0}", e.SignalTime);
        seconds += 5;
        count += 1;
        if (count>10000 || seconds==86400)
        {
            aTimer.Enabled = false;
            Console.WriteLine("\n\nTimer is off at {0}\n\n", e.SignalTime.TimeOfDay.ToString());
        }
     }
   }
 }

你的意思是這樣嗎?

Console.WriteLine("Limit = 10000");
Console.WriteLine("Count: {0} of 10000. {1} remaining", count, 10000 - count);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM