C# 如何检查计时器1是否已启动?
我已下载文件已完成事件:C# 如何检查计时器1是否已启动?,c#,.net,winforms,C#,.net,Winforms,我已下载文件已完成事件: private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { timer1.Stop(); span = new TimeSpan(0, (int)numericUpDown1.Value
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
timer1.Stop();
span = new TimeSpan(0, (int)numericUpDown1.Value, 0);
label21.Text = span.ToString(@"mm\:ss");
timer3.Start();
}
else if (!e.Cancelled)
{
timer3.Stop();
label19.Visible = false;
bool fileok = Bad_File_Testing(combinedTemp);
if (fileok == true)
{
File1 = new Bitmap(combinedTemp);
bool compared = ComparingImages(File1);
if (compared == false)
{
DirectoryInfo dir1 = new DirectoryInfo(sf);
FileInfo[] fi = dir1.GetFiles("*.gif");
last_file = fi[fi.Length - 1].FullName;
string lastFileNumber = last_file.Substring(82, 6);
int lastNumber = int.Parse(lastFileNumber);
lastNumber++;
string newFileName = string.Format("radar{0:D6}.gif", lastNumber);
identicalFilesComparison = File_Utility.File_Comparison(combinedTemp, last_file);
if (identicalFilesComparison == false)
{
string newfile = Path.Combine(sf, newFileName);
File.Copy(combinedTemp, newfile);
LastFileIsEmpty();
}
}
}
else
{
File.Delete(combinedTemp);
}
File1.Dispose();
}
}
如果e为错误,则计时器1为停止,计时器3为启动。
在timer3中,我试图在30秒后再次下载该文件。
然后在下一次到达完成的事件时,例如,这次e没有显示任何错误,因此将进入第二部分:
else if (!e.Cancelled)
{
timer3.Stop();
label19.Visible = false;
bool fileok = Bad_File_Testing(combinedTemp);
if (fileok == true)
{
File1 = new Bitmap(combinedTemp);
bool compared = ComparingImages(File1);
if (compared == false)
{
DirectoryInfo dir1 = new DirectoryInfo(sf);
FileInfo[] fi = dir1.GetFiles("*.gif");
last_file = fi[fi.Length - 1].FullName;
string lastFileNumber = last_file.Substring(82, 6);
int lastNumber = int.Parse(lastFileNumber);
lastNumber++;
string newFileName = string.Format("radar{0:D6}.gif", lastNumber);
identicalFilesComparison = File_Utility.File_Comparison(combinedTemp, last_file);
if (identicalFilesComparison == false)
{
string newfile = Path.Combine(sf, newFileName);
File.Copy(combinedTemp, newfile);
LastFileIsEmpty();
}
}
}
else
{
File.Delete(combinedTemp);
}
File1.Dispose();
}
但由于第一次出现错误,我停止了timer1,这次没有错误,所以我想启动timer1,但在构造函数中,我启动了timer1,它试图第一次下载一个文件,因此可能会出现完全没有错误的情况,并且它将一直到达完成事件的第二部分
我可以在任何情况下输入完成的事件timer1.Start();问题是,如果计时器1已经启动并且没有停止,那么每次重新启动都会出现问题吗
这就是为什么我想检查计时器1是否已经运行,不要再次启动它。您可以检查
timer1.Enabled
值
如果计时器当前已启用,则为true;否则,错误。默认值
是假的
我没有试图弄清楚您是否真的需要检查这个,但是如果您正在使用,那么会有一个属性告诉您它当前是否正在运行。clcto您是否正确检查timer1是否已启用真的执行了此操作。谢谢。@yairshalvi如果他做了,回答你的问题。你应该让他回答,并把它标为“已回答”。