preventing second application instance starting

G

Guest

Hello. I have written a simple image viewer application using C# .NET.
It only needs to display one image at a time. When a different program, in
C, running on the same machine, does a
"system(myfile.a2d2)" call, it automatically starts my image viewer
application (using file type association). a2d2 is the image file
format, my own. If the C program does the system call again for a
different image, I find that it starts a new instance of my image
viewer application running. I would like to have it so that the
already-running instance senses that another image is to be loaded,
and loads it, rather than starting a whole second instance of the
application. Any help on this OS and application question would be
appreciated.
 
J

JohnFol

Hi John, have a look at this . . . It's not C# but not that difficult to
convert . .(if you want the original text look for PrevInstance in MSDN)



PrevInstance Property Changes in Visual Basic .NET
See Also
App Object Changes in Visual Basic .NET

In Visual Basic 6.0, the PrevInstance property of the App object was used to
determine if a previous instance of an application was running. There is no
equivalent for this property in Visual Basic .NET; however, the following
code can be used to test for a previous instance:

' Visual Basic .NET
Function PrevInstance() As Boolean
If
Ubound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName))
Return True
Else
Return False
End If
End FunctionNote The behavior is slightly different than that of Visual
Basic 6.0. In Visual Basic 6.0, PrevInstance returned true only if the full
path and file name were exactly the same; in Visual Basic .NET, this
function will return true for two instances started from different paths. In
addition, PrevInstance would never return true for the first instance of an
application; in Visual Basic .NET, once a second instance is loaded, the
first instance will also return true.
 
G

Guest

Hello John. That is quite useful to know, the PrevInstance property and the
code you attached. That will come in useful certainly. Thank you very much.
John
 

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