我检查form_load
事件的条件是否应该关闭表单窗口。如果是这样,将启动间隔为3000
的计时器,并且在勾选之后,应关闭表单。当我检查我的调试器时,即使条件返回true,调试器也跳过我的timer.Start()
方法,我的计时器永远不会被勾选。
我已将班级中的计时器定义为System.Windows.Forms.Timer timer;
,这就是我启动它的方式:
timer = new System.Windows.Forms.Timer();
this.timer.Enabled = true;
this.timer.Interval = 3000;
this.timer.Tick += new System.EventHandler(this.timer_Tick_1);
刻度事件:
private void timer_Tick_1(object sender, EventArgs e)
{
this.Close();
}
条件很简单:
if (closeWindow)
timer.Start();
相信我,closeWindow
会返回true
。
P.S。奇怪的是,这个计时器曾经工作过。我知道我也许把它搞砸了。但我不知道在哪里。
更新: form_load事件
private void FormMain_Load(object sender, EventArgs e)
{
metroLabelBuild.Text = args["name"] + " " + args["action"];
if (CheckArguments(args, 18))
{
try
{
campaignRecipientsFileLocation = args["recipientsfile"].Trim();
campaignName = args["name"].Trim();
campaignDescription = args["description"].Trim();
campaignAction = args["action"].Trim();
campaignOutputFormat = args["outputformat"].Trim();
campaignType = args["type"].Trim().ToLower();
campaignDelimiter = args["delimeter"].Trim();
campaignOutputPath = args["outputpath"].Trim();
campaignFileName = args["filename"].Trim();
campaignId = Convert.ToInt64(args["id"].Trim());
campaignFixedCost = Convert.ToInt32(args["fixedcost"]);
campaignVariableCost = Convert.ToInt32(args["variablecost"]);
campaignControlGroup = Convert.ToInt32(args["controlgroup"]);
campaignFtpId = Convert.ToInt64(args["ftpid"].Trim());
campaignHasSpyList = (args["hasspylist"].ToLower().Equals("true") || args["hasspylist"].Equals("1")) ? true : false;
closeWindow = (args["closewindow"].ToLower().Equals("true") || args["closewindow"].Equals("1")) ? true : false;
campaignShouldUploadToFTP = (args["shoulduploadtoftp"].ToLower().Equals("true") || args["shoulduploadtoftp"].Equals("1")) ? true : false;
}
catch
{
listBoxMessages.Items.Add("Error preparing the arguments.");
continueProcess = false;
this.Close();
}
finally
{
logger = new Logger(loggerEnabled, cs);
fh = new FileHelper(logger);
rh = new RecipientHelper(logger);
dbh = new DatabaseHelper(logger, cs);
if (continueProcess)
{
InsertCampaignRun("Running");
RunCampaign();
if (closeWindow)
timer.Start();
}
}
}
else
{
if (closeWindow)
timer.Start();
}
}