471,339 Members | 1,250 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

preventing second application instance starting

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.

Jul 21 '05 #1
2 1879
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(Diag nostics.Process.GetCurrentProcess.ProcessName))
0 Then 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.

"johnmann56" <jo********@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com... 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.

Jul 21 '05 #2
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

"JohnFol" wrote:
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(Diag nostics.Process.GetCurrentProcess.ProcessName))
> 0 Then

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.

"johnmann56" <jo********@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
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.


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by whitehorse | last post: by
2 posts views Thread by Cramer | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.