【发布时间】:2016-08-02 22:20:28
【问题描述】:
所以,我的 Program.cs 中有这个 Exited 事件,其中我有我的应用程序的主要入口点。它打开另一个外部程序并监视其状态。如果这个外部程序关闭,它需要在最初打开的表单上弹出一个对话框。我知道如何捕获退出的事件,但我需要使用我想要执行的操作在另一个表单上调用或运行函数。
public static class Program
{
public static void ExternalProgramFunction()
{
System.Diagnostics.Process startExternal = System.Diagnostics.Process.Start("external.exe", String.Format(ConnectionArg));
startExternal.EnableRaisingEvents = true;
startExternal.Exited += ExternalProgramExits;
}
public static void ExternalProgramExits(object sender, EventArgs e)
{
if (UserClose == false)
{
/// Need code here to open dialog box on another form!!!
}
}
/// The main entry point for the application.
[STAThread]
static void Main(string[] arguments)
{
UserClose = false;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Manager());
我希望这段代码执行以下以另一种形式存在的函数。我这样做是为了打开对话框并阻止表单被点击。我在下面列出的是另一种形式的一些代码。我想从 Program.cs 运行prematureclosepopup
public Manager()
{
InitializeComponent();
}
public void PrematureClosePopup()
{
ManagerWarning messagepopup = new ManagerWarning();
messagepopup.ShowDialog();
}
【问题讨论】: