Solved

VB.net Application Talking to Another

Posted on 2011-03-24
9
620 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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