开发者

Best way to have an app interact with another running application

I am new at vb.net programming so please bear with me. I am trying to do the following, in a terminal server environment...

At user login, launch an app I have created. This app opens a web site in a webbrowser control, logs the user in to the web site, and parses links from the resulting web page. These links are links to launch citrix sessions on another farm.

Create another app that appears on the start menu for the logged in user. User clicks on this app, it communicates with the launch app to basically click the href associated with the citrix app within the webbrowser control. Then this app will go away...

I have already coded the first app and figured out how to click links within the webbrowser control. What I can't figure out is how to go about implementing the second app, that runs as a separate app, but communicates with the first app to do its business. I see a plethora of options such as MFC, AppDomains, RPC, and so on. My question is which is the best practice to have one app interact with another and have the other app take actions based on that interaction? I prefer to stick completely to vb.net.

A good example of how I would like this to work - a web browser (IE, FF, whatever) is open on the desktop, user clicks a link in an email, link ope开发者_JAVA技巧ns in running browser. An action in the mail client causes action in the browser.


In my case I find that using the My.Application.StartupNextInstance event meets my needs perfectly. Instead of using multiple apps use the same app, every time a duplicate instance is run it passes the command line arguments to the first instance.

But in all fairness to everyone who gave answers above, I believe the StartupNextInstance event is using WCF to do the passing. By using a single instance app via the framework I don't have to manually code all of the passing back and forth...


WCF pipe is great for interprocess Communication. Please check the following sample: http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication

It's in C# but you can easily translate it to VB.NET.


In order for two apps to communicate, you'll need some form of cross-process communications mechanism to allow a service (an app offering operations that can be called) to listen for incoming requests and for client(s) to call those exposed operations.

Your best bet for this is to use Windows Communication Foundation (WCF) to expose services from your first app that your second app can call.

I suggest you examine my Magic8BallService sample app at Codeplex. It's written in C#, but it's pretty simple and should give you most of the understanding you need in order to create what you're looking for.

HTH.


I would suggest WCF as well and found the following links good starting points:

  • Beginner's Guide to Windows Communication Foundation
  • Conceptual Overview
  • Configuring System-Provided Bindings
  • How to choose a WCF binding?


I prefer to use mutex to achieve this functionality
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

/**
* The idea here : we will using mutex to prevent run more than one instance from our application
*/
namespace ParallelDotNet.TaskProgramming
{
    class MutexAcrossApplications
    {
        public static void Run()
        {
            const string appName = "ThisIsOurUniquApplicationName965584";
            Mutex mutex;
            try
            {
                mutex=Mutex.OpenExisting(appName);
                Console.WriteLine($"Sorry You Cant Run Multible instance of this program : This is alredy Run");
            }
            catch (WaitHandleCannotBeOpenedException e)
            {
                Console.Write($"Welecom This is the first instance of this program");
                mutex=new Mutex(false,appName);
            }

            Console.ReadKey();
            mutex.ReleaseMutex();

        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜