如何按相反的顺序获得的计数

本文关键字:顺序 何按相 | 更新日期: 2023-09-27 18:26:28

如何以相反的顺序获得计数?现在,我已经显示了完成计数的次数。。但我也想要剩下的计数。在下面的程序中,我如何在每天结束时重置计时器并显示上次执行的时间?有人能帮我完成整个项目吗?程序是-

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);