?
Solved

VB.net Application Talking to Another

Posted on 2011-03-24
9
Medium Priority
?
629 Views
Last Modified: 2012-06-27
I have a situation where I have a third part provided application that can launch programs passing data from the UI screens to it as parameters. They have no other way to interact with data so this is what I have to use.

I have an application that is launched with the passed data on teh command line and it does its thing. The problem is I need a way to have a sort of "controller" application that will detect if the application is already open.. and if it is send the new info to the application so it can accept the new data. I dont want to close and reopen the application I prefer to just pass the new information and have the application change to this new data.

So what I need is to develop a calling application that will check to see if the app is open.. if it is not then open passing my info. If it is open I need to have this caller send this info to the currently running process and have that appilcation act on the new data.

Can anyone direct me here... is this WCF, sockets, or is there a much easier way to go about doing this? I have considered just using the registry as a staging ground and have it check every x ms and do something if the value changes.. sort of crappy idea though.
0
Comment
Question by:NTGuru705
9 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35211721
"I have an application that is launched with the passed data on teh command line and it does its thing."

Do you have the SOURCE CODE for this application?
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 35211832
you can start a program / process by calling process.start and provide any command  line options to it.

You can also use the invoke (as in p.invoke()), and with this you can keep in memory the process ids etc
0
 
LVL 28

Expert Comment

by:Ryan McCauley
ID: 35212408
If you have the source code for this application, you can set it up to receive wcf messages - just open a wcflistener when the application launches and then your "client" can send wcf messages to that endpoint whenever it wants to refresh the app. There are a number of examples online (google "wcf communications tcp port"), so I won't try to reproduce one here.

Another option is to have the "server" app create a filewatcher and watch some folder. When your "client" wants to send an update, it writes it to a file and the watcher sees it, picks it up, and processes it.
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.

 
LVL 1

Author Comment

by:NTGuru705
ID: 35212428
No I dont have source for the application I am integrating with but yes I have the source for the app I am opening from this program.

So there is a program lets call it Program A.
It allows me to launch another program from custom menu commands and pass as parameters information from the present working screen in that application.

THe application I am calling is Program B - I have the source.

I need to write Program C which can be called from Program A to send info to Program B if it is already open and if not just spawn Program B. I want the application Program B to stay open and just pass the new parameters to it.  I think WCF is a great option but the file watcher is a great idea too because there is no excessive "reading" going on. That may be my fastest route because I have experience with that. I want to stay away from TCP sockets if I can because it will be running on a terminal server and I dont want to have to manage ports and such.

I think I will go with the file watcher and see how it responds. If it is not fast enough I can try to figure out the WCF stuff.
Thank you for your help
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35212547
There is an easier solution using the Application.StartupNextInstance() event:
http://msdn.microsoft.com/en-us/library/b9z4eyh8(VS.90).aspx
http://msdn.microsoft.com/en-us/library/w3xx6ewx(VS.90).aspx

Just check the "Make single instance application" box in Project --> Properties.

Now you can use "Process.Start(ProcessBFullPathFilename, ProcessB_Parameters)" regardless of whether Process B is running or not.

If Process B is not running then it will get the Startup() event.
If Process B is already running then it will get the StartupNextInstance() event.

There will only ever be ONE instance of Process B running though.
0
 
LVL 1

Author Comment

by:NTGuru705
ID: 35212625
In the make single instance application... that applies only to the current session right?
So on a terminal server more than one user could run it but per session only one - am i understanding that right?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35212632
Not sure about the sessions issue as I don't work them...sorry.
0
 
LVL 1

Author Comment

by:NTGuru705
ID: 35212639
I seem to be getting this error:


Error      1      Event 'StartupNextInstance' cannot be found.
Private Sub MyApplication_StartupNextInstance( _
ByVal sender As Object, _
ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
        Dim inputArgument As String = "/input="
        Dim inputName As String = ""

        For Each s As String In e.CommandLine
            If s.ToLower.StartsWith(inputArgument) Then
                inputName = s.Remove(0, inputArgument.Length)
            End If
        Next

        If inputName = "" Then
            MsgBox("No input name")
        Else
            MsgBox("Input name: " & inputName)
        End If
    End Sub

Open in new window


0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35212666
You have to put it in the a special place.

Click on Project --> Properties.
Then click on the "View Application Events" button in the bottom right.
Across the top of the IDE, change the two dropdowns:
    Left DropDown: "MyApplication" --> "(MyApplication Events)"
    Right DropDown: "(Declarations)" --> "StartupNextInstance"
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question