从C#,打开任意应用程序 [英] From C#, open an arbitrary application

查看:165
本文介绍了从C#,打开任意应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关问题[计算器] 这里

Related question [stackoverflow] here.

我试图做上述情况,但我想利用这个过程又进了一步。我想用的文件类型的默认编辑器中打开任意文件。从这一点来说,我希望让我的用户以该文件,因为他们通常会相互作用,还是继续在我的应用工作。该扩展是用户完成编辑后会发生什么。有没有一种方法,我可以从外部应用程序捕获接近(理想情况下保存)事件,并使用它作为触发器来做些别的事情?对于我而言,跟踪外部应用程序会做的结束。

I'm trying to do the above, but I want to take the process one step further. I want to open an arbitrary file using the default editor for the file type. From that point, I want to allow my user to interact with the file as they would normally, or continue to work in my application. The extension is what happens after the user finishes editing. Is there a way I can capture a close (and ideally save) event from the external application and use that as a trigger to do something else? For my purposes, tracking the closing of the external application would do.

我可以在特定的情况下做到这一点。例如,我可以从我的应用程序中打开一个Word实例,并跟踪自己感兴趣我的应用程序的事件。不过,我想脱夫妇Word.I我的应用程序需要让我的用户使用自己选择的任何文档编辑器,然后管理文件的存储被离散编辑在幕后。

I can do this in the specific case. For example, I can open a Word instance from my application and track the events that interest my application. However, I want to de-couple my application from Word.I want to allow my users to use any document editor of their choice, then manage the storage of the file being edited discretely behind the scenes.

推荐答案

您可以用类似的引用问题的方式做到这一点,但语法稍有不同:

You can do this in a manner similar to the referenced question, but the syntax is slightly different:

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = 
    new System.Diagnostics.ProcessStartInfo("C:\...\...\myfile.html");
process.Start();
process.WaitForExit(); // this line is the key difference



在WaitForExit()调用将阻塞,直到其他应用程序关闭。你可以使用这个代码在一个单独的线程中,这样用户可以继续使用在此期间您的应用程序。

The WaitForExit() call will block until the other application is closed. You would use this code in a separate thread so that the user can keep using your application in the meantime.

这篇关于从C#,打开任意应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆