File associations and running only one instance of the application.

  • Thread starter Thread starter rollasoc
  • Start date Start date
R

rollasoc

Hi,

I'm trying to implement file associations with my application. I've been
doing this in phases and I'm stuck at the last hurdle.

Phases
1) Installer sets up the file association
Main in my application changed to accept a string [] args parameter
then creates my class passing in the string [] args parameter
On loading the form if the passed in parameter is a string it
loads the file

This works fine.
When I double click on an assoociated file I get a new instance of the form.

2) The boss says he only wants one instance of the application to run

In Main check to see if the application is in the running processes list
if it is don't run
This works fine.

The bit I'm having trouble is that if it is in the running list I want
to call that process and tell it to load
the filename passed in.

Any ideas how to do this? I think the issue I'm having is the class is
not static and the Main function is.

Do I need to store a static reference to the form created and then use
Invoke on a delegate?

rollasoc
 
Ok sorted it out now with the cunning use of SendMessage and WM_COPYDATA to
post a message to the first instances window.

rollasoc
 
Back
Top