C# 如何以相反的顺序获得的计数?
如何按相反的顺序计算计数?现在,我已经显示了已完成计数的数量。。但我还想要剩下的计数。我如何在每天结束时在下面的程序中重置计时器,并显示上次执行计时器的时间?有人能帮我完成整个计划吗? 该计划是——C# 如何以相反的顺序获得的计数?,c#,.net,c#-4.0,c#-3.0,C#,.net,C# 4.0,C# 3.0,如何按相反的顺序计算计数?现在,我已经显示了已完成计数的数量。。但我还想要剩下的计数。我如何在每天结束时在下面的程序中重置计时器,并显示上次执行计时器的时间?有人能帮我完成整个计划吗? 该计划是—— namespace Time_Writer { class Program { static int count = 1; static double seconds; private static System.Timers.Timer aTimer;
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);
你能解释一下你的程序应该做什么吗?它为什么要写入文件?它读的是什么?@gideon我不认为这里发布的所有代码都不需要回答他的问题。@gideon实际上这个程序每天要重复给定的语句10k次。。我可以插入邮件并将其发送给不同的收件人,而不是声明。它会写入一个文件,因为我需要记录已发送邮件和剩余邮件的数量。你能帮我吗?@Jayanga那又怎样?我只是把它贴了出来,这样人们就可以看到这个节目是关于n的,然后得到一个线索..嘿,是的。。非常感谢:)但是我如何保存上次执行时的“日期和时间”,并在每次新执行时显示它,以及以前的日期和时间。。希望你明白我的意思。。