表单加载/后台工作代码完成后关闭应用程序 [英] Close Application after form load/backgroundworker code completes
本文介绍了表单加载/后台工作代码完成后关闭应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应用程序,它在form_load或backgroundworker中完成所有这些工作。我想做的是,一旦backgroundworker完成所有工作,应用程序就会自动关闭。这是我的代码:
I have an app that is doing all of it''s work in either the form_load or the backgroundworker. What I would like to do is make the application close itself once all of the work done by the backgroundworker is completed. Here is my code:
private void Form1_Load(object sender, System.EventArgs e
{
timer1.enable = true;
timer1.interval = 1000;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Visible = !label1.Visible;
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
progressBar1.Value = 200;
ServiceController serviceController = new ServiceController("Spooler");
serviceController.Stop();
progressBar1.Value = 400;
serviceController.Start();
Thread.Sleep(3000);
progressBar1.Value = 600;
foreach (string path in Directory.GetFiles("C:\\Windows\\System32\\spool\\PRINTERS"))
File.Delete(path);
progressBar1.Value = 800;
string szString = "~JR";
PrintDialog printDialog = new PrintDialog();
printDialog.PrinterSettings = new PrinterSettings();
printDialog.PrinterSettings.PrinterName = "Label Printer";
Form1.RawPrinterHelper.SendStringToPrinter(printDialog.PrinterSettings.PrinterName, szString);
progressBar1.Value = 1000;
}
}
}
我只是希望它运行直到它完成然后自动终止表单。有什么想法吗?
I just want it to run until it''s complete and then kill the form automatically. Any ideas?
推荐答案
怎么样......
How about...
this.Close();
这篇关于表单加载/后台工作代码完成后关闭应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文