How to Send File to Running Application

P

PJ Olson

I have an app that allows only one instance to run at a time. I have a file
extension associated with this app and would like to pass a running instance
the file name if a user double-clicks the file directly.

Any help would be greatly appreciated.

PJ
 
N

Nicholas Paldino [.NET/C# MVP]

PJ,

It's a little complicated, but it is possible. First, you would need to
create a remoting server in your application, such that the application that
is the only one running would be the one that is the server. This would
have a method which would take a filename to process.

Then, in the code for the beginning of your app, if you determine that
your app is to be shut down (because another instance is running), you would
hook up to the remoting server that the other app is hosting, and make the
call, passing the filename to process (it should be part of the command line
parameters).

If you are using .NET 2.0, all of this is done for you. There is an
question in the current issue of MSDN magazine in the ".NET Matters"
section. The question regards single-instance applications, and the answer
shows how all of this is done for you. You can find it at (watch for line
wrap):

http://msdn.microsoft.com/msdnmag/issues/05/09/NETMatters/default.aspx

Hope this helps.
 
P

PJ Olson

That is very helpful!

Thanks,
PJ

Nicholas Paldino said:
PJ,

It's a little complicated, but it is possible. First, you would need
to create a remoting server in your application, such that the application
that is the only one running would be the one that is the server. This
would have a method which would take a filename to process.

Then, in the code for the beginning of your app, if you determine that
your app is to be shut down (because another instance is running), you
would hook up to the remoting server that the other app is hosting, and
make the call, passing the filename to process (it should be part of the
command line parameters).

If you are using .NET 2.0, all of this is done for you. There is an
question in the current issue of MSDN magazine in the ".NET Matters"
section. The question regards single-instance applications, and the
answer shows how all of this is done for you. You can find it at (watch
for line wrap):

http://msdn.microsoft.com/msdnmag/issues/05/09/NETMatters/default.aspx

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

PJ Olson said:
I have an app that allows only one instance to run at a time. I have a
file extension associated with this app and would like to pass a running
instance the file name if a user double-clicks the file directly.

Any help would be greatly appreciated.

PJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top