Process.Start – Force new process

Applications like notepad++, Acrobat Reader and so on, will not necessarily create a new process when you open a file using Process.Start, but instead just open a new tab.

I know that there are specific command line arguments for those applications that can prevent this, but I am more interested if there is a general way of doing so?

The requirement is, that we need to reliably know when a user edits and exits a document, that was opened from within our application.
But these kind of applications make it really hard since the lifetime of the Process is not a reliable indicator.

>Solution :

In general, the behavior of whether a new process is created or a new tab is opened when using Process.Start to open a file depends on how the target application is designed. Some applications have command line arguments or settings that allow them to be configured to either open a new process or open a new tab within an existing process.

However, if the target application does not provide a specific command line argument or setting to control this behavior, there is no general and reliable way to force it to open a new tab instead of a new process. The decision of how the application handles file opening is ultimately up to the application itself.

To address your requirement of reliably knowing when a user edits and exits a document opened from within your application, you could consider alternative approaches:

  • Monitor the file system: Instead of relying on the process, you can monitor the file system for changes to the file. You can use file system monitoring APIs in C# such as FileSystemWatcher to detect modifications or updates to the file. This is probably your best option.

  • Use inter-process communication: If the target application supports inter-process communication, you can establish a communication channel between your application and the target application. This way, you can send messages or notifications when the user edits or exits the document.

  • Explore application-specific APIs: Some applications provide APIs or libraries that you can integrate with to get more fine-grained control and notifications about document editing and closing events. You would need to research the specific application you are interested in to see if such APIs are available. That is if you are looking to integrate another app to your C# app’s workflow.

Remember that these approaches may require additional research and implementation efforts, and their availability and effectiveness depend on the specific target application you are working with.

Hope this helps.

Leave a Reply