Click here to Skip to main content
15,895,808 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using Generic Method to Determine if All Elements in an Array is Zero Pin
Adam Maras11-Mar-09 13:32
Adam Maras11-Mar-09 13:32 
GeneralRe: Using Generic Method to Determine if All Elements in an Array is Zero Pin
mfcuser12-Mar-09 4:29
mfcuser12-Mar-09 4:29 
GeneralRe: Using Generic Method to Determine if All Elements in an Array is Zero Pin
mfcuser12-Mar-09 5:08
mfcuser12-Mar-09 5:08 
QuestionHiding an empty Column in Gridview Pin
edcorusa11-Mar-09 11:31
edcorusa11-Mar-09 11:31 
AnswerRe: Hiding an empty Column in Gridview Pin
dataminers11-Mar-09 12:10
dataminers11-Mar-09 12:10 
GeneralRe: Hiding an empty Column in Gridview Pin
edcorusa13-Mar-09 7:51
edcorusa13-Mar-09 7:51 
GeneralRe: Hiding an empty Column in Gridview Pin
dataminers13-Mar-09 21:25
dataminers13-Mar-09 21:25 
QuestionDelegates for instance methods across appdomains... [modified] Pin
MrBhbk11-Mar-09 8:57
MrBhbk11-Mar-09 8:57 
I have been building a GUI that interfaces with 3 services via remoted interfaces. I'm using GenuineChannels (http://www.genuinechannels.com) broadcast engine as the framework for event based communication between services & the GUI. Since you can only register one remoted object per AppDomain (I hope that statement is correct), I've had to create a seperate AppDomain for each UserControl in the GUI so more than one remoted object can be registered. Each UserControl contains a TreeView that needs to be updated via the broadcast engine, or remoted events. Everything appears to be working just as I had hoped, but here is my problem. I've tried using different types of delegates at different scopes within the code & also tried refactoring my code, but I cannot seem to come up with a way to update the TreeView instance within the UserControl from a remoted object in a seperate AppDomain. Here's most of the code from the classes involved. Unimportant peices have been removed.

namespace Console
{
public partial class ControlDelegate : UserControl
{
public ControlDelegate()
{
InitializeComponent();

// Create appdomainsetup information for the new appdomain.
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = System.Environment.CurrentDirectory;
setup.ApplicationName = ("Delegate-" + AppDomain.CurrentDomain.FriendlyName);

//Create evidence for new appdomain.
Evidence evidence = AppDomain.CurrentDomain.Evidence;

// Create the application domain.
AppDomain domain = AppDomain.CreateDomain(("Delegate-" + AppDomain.CurrentDomain.FriendlyName), evidence, setup);
DelegateMessenger remote = (DelegateMessenger)domain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, Assembly.GetCallingAssembly().GetName().Name + ".DelegateMessenger");
Thread thread = new Thread(new ThreadStart(remote.Construct));
thread.Start();
}

/****************************/
this method must be static to refer to it, which is my problem.
/****************************/
public static void tViewDelegateHeartBeat(Objects.Message message, String nickname)
{
System.Console.WriteLine(message.action);

/****************************/
The line below is all that I need to make project functional.
/****************************/
//tViewDelegate.Nodes.Add(message.action + " " + nickname);
}
}
public class DelegateMessenger : MarshalByRefObject, IDelegateMessenger
{
public static String Nickname = "Delegate-" + Assembly.GetExecutingAssembly().GetName().Name;
public static DelegateMessenger Instance = new DelegateMessenger();
public static IDelegateChat iDelegateChat;
public static IDelegateServer iDelegateServer;
public static Object IDelegateChatLock = new Object();

public void Construct()
{
try
{
// Setup remoting with assembly objects as remote object.
IDictionary props = new Hashtable();
props["name"] = "gtcpd";
props["prefix"] = "gtcpd";
props["priority"] = "100";
props["port"] = "0";

GenuineTcpChannel channel = new GenuineTcpChannel(props, null, null);
ChannelServices.RegisterChannel(channel, false);
WellKnownClientTypeEntry remotetype = new WellKnownClientTypeEntry(typeof(SharedChannels.GenuineTcp.GenuineTcpChannel), "gtcpd://127.0.0.1:48886/DelegateMessenger");
RemotingConfiguration.RegisterWellKnownClientType(remotetype);

// Bind client's receiver.
RemotingServices.Marshal(Instance, "DelegateMessenger");

// Subscribe to the chat event.
lock (IDelegateChatLock)
{
iDelegateServer = (IDelegateServer)Activator.GetObject(typeof(IDelegateChat), "gtcpd://127.0.0.1:48886/DelegateServer");
iDelegateChat = iDelegateServer.JoinDialog(Nickname);
}
}
catch (Exception ex)
{
MessageBox.Show(Environment.NewLine + String.Format("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace));
}
}
public Object ReceiveMessage(Objects.Message message, String nickname)
{
/*****************************/
this works fine if the receiving function is static, but I
need to refer to an instance method to be able to update
the UserControl TreeView (tViewDelegate).
/*****************************/
AppDomain.CurrentDomain.DoCallBack(delegate { ControlDelegate.tViewDelegateHeartBeat(message, nickname); });

/*****************************/
this works if I register only one remoted object within
the GUI AppDomain, which won't work with my current design
since I need to access several remoted objects from other UserControls.
/*****************************/
// http://blogs.msdn.com/csharpfaq/archive/2004/03/17/91685.aspx
/* if (tViewDelegate.IsHandleCreated)
{
try
{
tViewDelegate.Invoke(new tViewDelegateCallback(this.tViewDelegateHeartBeat), new Object[] { message, nickname });
}
catch (Exception ex)
{
MessageBox.Show(Environment.NewLine + String.Format("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace));
}
}
*/
return null;
}
public override Object InitializeLifetimeService()
{
return null;
}
}
}

I'm hoping someone sees something silly that I'm doing and can point it out. The project is still in its infancy, so I could refactor everything if need be. Any ideas?

modified on Wednesday, March 11, 2009 3:42 PM

Generali created VSTO 2003 addin for outlook inspector. i need help in Pin
Arun Kumar A.S11-Mar-09 7:57
Arun Kumar A.S11-Mar-09 7:57 
GeneralRe: i created VSTO 2003 addin for outlook inspector. i need help in Pin
dataminers16-Mar-09 7:03
dataminers16-Mar-09 7:03 
QuestionProblem with webservice! Pin
Bryan Karlsson11-Mar-09 7:56
Bryan Karlsson11-Mar-09 7:56 
AnswerRe: Problem with webservice! Pin
J$11-Mar-09 9:37
J$11-Mar-09 9:37 
AnswerRe: Problem with webservice! Pin
Christian Graus11-Mar-09 9:37
protectorChristian Graus11-Mar-09 9:37 
GeneralRe: Problem with webservice! Pin
Bryan Karlsson11-Mar-09 12:47
Bryan Karlsson11-Mar-09 12:47 
AnswerRe: Problem with webservice! Pin
dataminers11-Mar-09 12:01
dataminers11-Mar-09 12:01 
AnswerRe: Problem with webservice! Pin
King Julien11-Mar-09 21:03
King Julien11-Mar-09 21:03 
QuestionMicrosoft Dynamics Retail Management System (RMS) Pin
info011-Mar-09 5:41
info011-Mar-09 5:41 
AnswerRe: Microsoft Dynamics Retail Management System (RMS) Pin
Le centriste11-Mar-09 7:58
Le centriste11-Mar-09 7:58 
QuestionWindows speech Pin
half-life11-Mar-09 4:54
half-life11-Mar-09 4:54 
AnswerRe: Windows speech Pin
Xmen Real 11-Mar-09 5:22
professional Xmen Real 11-Mar-09 5:22 
GeneralRe: Windows speech Pin
Nagy Vilmos11-Mar-09 5:35
professionalNagy Vilmos11-Mar-09 5:35 
GeneralRe: Windows speech Pin
Xmen Real 11-Mar-09 5:41
professional Xmen Real 11-Mar-09 5:41 
GeneralRe: Windows speech Pin
Nagy Vilmos11-Mar-09 5:51
professionalNagy Vilmos11-Mar-09 5:51 
GeneralRe: Windows speech Pin
Xmen Real 11-Mar-09 6:12
professional Xmen Real 11-Mar-09 6:12 
GeneralRe: Windows speech Pin
Nagy Vilmos11-Mar-09 6:22
professionalNagy Vilmos11-Mar-09 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.