Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 18th, 2006, 08:34 PM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to call a method on a remote object

I have some code in which I use System.Runtime.InteropServices.Marshal.GetActiveOb ject to get a reference to an instance of a form that is already running and would like to make a call to a method of this instance. What I am trying to accomplish is to have only one instance of my application running at one time, but to have each following instance send parameters to the one already running. The application has a main entry point outside of the form and in this EntryPoint.cs class I have code to check if there is already an instance of the application in the ROT (Running Object Table) and if there is already an instancec running I would like to pass parameters to the form and then call the form's Show() method so that it can refresh the GUI with the new parameters. I have everything running except for the exception that I get when trying to call a method on the already running instance of the form. The exception message is: {"This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server." }

Does someone have any idea of what is the correct way of calling a method on such a class. I have already searched for topics on .NET remoting, but they all point to a client and server and a TCP or HTTP Chanell, wich kind of confuses me since I do not think I need a Channel using those protocols.


Here is the code I have at the moment:


Code:
try 
                {
                    MessageBox.Show("trying to get form from ROT table");

                    Object objMainForm = System.Runtime.InteropServices.Marshal.GetActiveObject("XimisRadTransSolution.MainForm");
                    MessageBox.Show("got object obj main form");
                    theForm = (MainForm)objMainForm;
                    MessageBox.Show("casting the form");
                    theForm.setParams(argHashTable);
                    MessageBox.Show("already passed parameters");
                    theForm.Show();
                } 
                catch (Exception e) 
                {}


 
Old July 21st, 2006, 10:17 AM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

An easier way to figure out if another one of your applications is open is to use the Win32 FindWindow approach. The class below will allow you to search for a window according to the title or the name of the class that was used to create it. Simply, stop loading the new application instance if you find a window with the name you are looking for. Seems easier to me at least. If you need control of the other window for some reason, this isn't the right way to go though.


public class Win32
{
[DllImport("user32.dll")]
public static extern int FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
}


www.CoderForRent.com
Get A Computer Job!

www.ComputersComplete.com
Computer Parts & Accessories





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a function on every method call Takashi321 General .NET 1 September 21st, 2007 09:33 AM
Method to check Size of Remote File alex.zeal PHP How-To 0 September 20th, 2007 06:23 AM
Can I call a method that populate a Label??? cp75 ASP.NET 1.0 and 1.1 Basics 2 January 12th, 2007 05:39 AM
object parameters to remote method calls DotNetJunk General .NET 1 April 29th, 2005 04:02 AM
call remote native program, rmi? shi Java Espanol 1 March 28th, 2005 09:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.