PC Review


Reply
Thread Tools Rate Thread

Controle one application from another

 
 
Fredrik Andersson
Guest
Posts: n/a
 
      16th Sep 2004
Hi

I have a problem, I need to controle one app from another application. If I
press a button in app1 then somthing is going to happend in app2.

I hope somone understands what I mean.

Thanks
- Fredrik


 
Reply With Quote
 
 
 
 
Michael Kremser
Guest
Posts: n/a
 
      16th Sep 2004
Fredrik Andersson wrote:

> I have a problem, I need to controle one app from another application. If I
> press a button in app1 then somthing is going to happend in app2.


I think remoting will be right for you. If you decide to do so, follow
these instructions:

1.

Create a interface, that contains all the methods that app2 shoud be
able to do.

2.

In app2, declare these using's and this object:

using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;

....

private IChannel channel1 = null;

At the time, where the application should start "listening" to commands,
insert about this code (customize port number and service name):

channel1 = new TcpChannel(12345);
ChannelServices.RegisterChannel(channel1);
RemotingServices.Marshal(this,"MyApp2.rem");

3.

In app1, simply add this code (again, change port number and service
name as you did above, and the name of the interface (IYourInterface)):

string strConnectionString = "tcp://" + Host + ":12345/MyApp2.rem";
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel);

IYourInterface x =
(IYourInterface)Activator.GetObject(typeof(IYourInterface),strConnectionString);
if (x==null)
{
// something went wrong
}
else
{
// call any methods here
}

May be in your case it's clever to define "x" (please use a good name
for this object) at class level, run the activation at start up of your
application and in the button's click event, check whether x is null or
not and do the things you want.

HTH,

Michael

--
http://www.mkcs.at/
The specified e-mail-address is valid and will be read.
 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      16th Sep 2004
Hi,

You may need to define a protocol to send commands to the target
application. if you give more details a better solution can be proposed.


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation




"Fredrik Andersson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
>
> I have a problem, I need to controle one app from another application. If

I
> press a button in app1 then somthing is going to happend in app2.
>
> I hope somone understands what I mean.
>
> Thanks
> - Fredrik
>
>



 
Reply With Quote
 
Fredrik Andersson
Guest
Posts: n/a
 
      16th Sep 2004
Thanks Michael

Is there no posibility to do app2 as a com object in some way. It's just a
fiew of the functions i need to use and I know that both of them will be on
the same computer

"Michael Kremser" <mkspamx-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Fredrik Andersson wrote:
>
> > I have a problem, I need to controle one app from another application.

If I
> > press a button in app1 then somthing is going to happend in app2.

>
> I think remoting will be right for you. If you decide to do so, follow
> these instructions:
>
> 1.
>
> Create a interface, that contains all the methods that app2 shoud be
> able to do.
>
> 2.
>
> In app2, declare these using's and this object:
>
> using System.Runtime.Remoting;
> using System.Runtime.Remoting.Channels;
>
> ...
>
> private IChannel channel1 = null;
>
> At the time, where the application should start "listening" to commands,
> insert about this code (customize port number and service name):
>
> channel1 = new TcpChannel(12345);
> ChannelServices.RegisterChannel(channel1);
> RemotingServices.Marshal(this,"MyApp2.rem");
>
> 3.
>
> In app1, simply add this code (again, change port number and service
> name as you did above, and the name of the interface (IYourInterface)):
>
> string strConnectionString = "tcp://" + Host + ":12345/MyApp2.rem";
> TcpChannel channel = new TcpChannel();
> ChannelServices.RegisterChannel(channel);
>
> IYourInterface x =
>

(IYourInterface)Activator.GetObject(typeof(IYourInterface),strConnectionStri
ng);
> if (x==null)
> {
> // something went wrong
> }
> else
> {
> // call any methods here
> }
>
> May be in your case it's clever to define "x" (please use a good name
> for this object) at class level, run the activation at start up of your
> application and in the button's click event, check whether x is null or
> not and do the things you want.
>
> HTH,
>
> Michael
>
> --
> http://www.mkcs.at/
> The specified e-mail-address is valid and will be read.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MIDI controle in C# Per Friis Microsoft C# .NET 1 14th Feb 2008 02:06 PM
Treeview + Controle t Microsoft Dot NET 1 1st Dec 2005 02:32 AM
Controle parental Emmanuel Freeware 5 2nd Oct 2005 04:07 PM
How to use WebBrowser controle in Pocket PC application Joby Microsoft Dot NET Compact Framework 1 13th May 2004 02:33 PM
controle + enter Eli Aran Windows XP Basics 4 8th Nov 2003 03:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 AM.