[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

HOWTO: Detect duplicate application is running, send a message to the application and close the new one.

I added an event on the Windows right click menu for the .DOC extension.  I have this function calling a VB.NET program and passing the filename/path of the selected file.  If multiple files are selected, it calls the application as many times as you have files selected but I want one instance of the application to receive all of the filenames.

So I was thinking if the application would detect if another one is running, send that application the filename and close itself.  Maybe someone has a better idea how to handle this as well?
0
fishrich
Asked:
fishrich
  • 2
  • 2
  • 2
  • +1
1 Solution
 
bman9111Commented:
I have this code I use that detect if another application is running not sure if it will help

in my module I have

public sub main ()
 If PrevInstance() Then
            MessageBox.Show("This Application is Already Running!", "Halt", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Application.Exit()
            Exit Sub
        End If

end sub



    Private Function PrevInstance() As Boolean
        If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

0
 
S-TwilleyCommented:
Hi bman...  that solves the easier part of the question... but it leaves the harder part which Im unsure of (hence me not posting any comments)... being able to send a message back to the initial instance...

It's almost like the Picture Viewer you get in windows... if it's not already running and you open a picture, it'll open an instance and give you a preview... but if you try to preview a picture and an isntance of the Picture Viewer is already open, it sends a message to that instance saying to preview a certain file, and then closes itself down (leaving the original instance)
0
 
S-TwilleyCommented:
I believe I've seen something before relating to this topic, about using Named Pipes (or something similar to that)... but I've yet to use them
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Erick37Commented:
Here is a sample application which may help out.  As it turns out, Microsoft has not made it easy to do this in .NET (what a surprise).  You would think that such a common functionality would be supported by managed code - but it seems it is not.

Single Instance App with Command-Line Parameters
http://www.codeproject.com/vb/net/singleinstance.asp
0
 
fishrichAuthor Commented:
Thanks for all of the comments and suggestions.  I will review the links and let you all know if I find a solution.  Thanks again!
0
 
fishrichAuthor Commented:
It looks like Erick37's link should do what I need.. Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now