跟踪另一个应用程序

24 浏览
0 Comments

跟踪另一个应用程序

如何让我的主应用程序打开一个独立的应用程序,并在独立应用程序关闭时调用主应用程序中的一个事件?

目前我正在使用以下代码:

Process.Start("notepad.exe", "C:\test.txt");

我希望实现的目标是,在独立应用程序保存并关闭后,主应用程序能重新读取test.txt文件的内容。

0
0 Comments

问题的出现原因:主应用程序需要在另一个应用程序关闭时调用一个事件,但是不想让主应用程序等待。

解决方法:使用进程的Exited事件而不是使用线程来避免阻塞程序。

文章内容如下:

Dim Process As Process = new Process()
Process.StartInfo = new ProcessStartInfo("notepad", "C:\test.txt")
Process.Start()
Process.WaitForExit()
// Do something
Thanks, but I don't want the main application to have to wait. I just want it to call an event once notepad closes.
What was the purpose of the @?
You noticed that before I rolled it back huh? Sorry about that! It's a C# thing, which I thought would be the same in VB. It isn't: How to do a verbatim string literal in VB.NET?
If you don't want to block the program you can use the Process.Exited event rather than using threads.
Lol, good spot! (In case you hadn't already noticed, C# and VB are basically identical, ignoring these little differences)

文章结束。

0