Click here to Skip to main content
15,846,144 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionProblem to communicate between forms [modified] Pin
roshihans14-Mar-09 4:44
roshihans14-Mar-09 4:44 
AnswerRe: Problem to communicate between forms Pin
N a v a n e e t h14-Mar-09 7:00
N a v a n e e t h14-Mar-09 7:00 
GeneralRe: Problem to communicate between forms Pin
roshihans14-Mar-09 17:08
roshihans14-Mar-09 17:08 
GeneralRe: Problem to communicate between forms Pin
N a v a n e e t h14-Mar-09 17:21
N a v a n e e t h14-Mar-09 17:21 
GeneralRe: Problem to communicate between forms Pin
roshihans14-Mar-09 18:33
roshihans14-Mar-09 18:33 
GeneralRe: Problem to communicate between forms Pin
N a v a n e e t h15-Mar-09 6:14
N a v a n e e t h15-Mar-09 6:14 
GeneralRe: Problem to communicate between forms Pin
roshihans15-Mar-09 19:12
roshihans15-Mar-09 19:12 
QuestionDelegates for instance methods between AppDomains... Pin
MrBhbk11-Mar-09 11:28
MrBhbk11-Mar-09 11:28 
I've already posted this on the C# forum, but since I will be implimenting it in managed c++ soon after, I thought I would just run it by you folks also.

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 messages from 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 part of the update to TreeView instance, but it's
the root of my problem right now.
/****************************/
//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 within the GUI.
/*****************************/
// 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?
QuestionSingle Textbox EventHandler for all Pin
Badboy22TR9-Mar-09 15:23
Badboy22TR9-Mar-09 15:23 
AnswerRe: Single Textbox EventHandler for all Pin
ky_rerun10-Mar-09 6:00
ky_rerun10-Mar-09 6:00 
AnswerRe: Single Textbox EventHandler for all Pin
Badboy22TR10-Mar-09 13:07
Badboy22TR10-Mar-09 13:07 
QuestionUpdating a label's text automatically? (New programmer) Pin
TabascoSauce9-Mar-09 13:50
TabascoSauce9-Mar-09 13:50 
GeneralRe: Updating a label's text automatically? (New programmer) Pin
Luc Pattyn9-Mar-09 14:09
sitebuilderLuc Pattyn9-Mar-09 14:09 
GeneralRe: Updating a label's text automatically? (New programmer) Pin
TabascoSauce9-Mar-09 15:10
TabascoSauce9-Mar-09 15:10 
QuestionInt64 minus.... Pin
Thilek8-Mar-09 7:46
Thilek8-Mar-09 7:46 
AnswerRe: Int64 minus.... Pin
Mark Salsbery8-Mar-09 10:19
Mark Salsbery8-Mar-09 10:19 
AnswerRe: Int64 minus.... Pin
Dave Doknjas8-Mar-09 14:56
Dave Doknjas8-Mar-09 14:56 
Question(C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
zkii4-Mar-09 4:08
zkii4-Mar-09 4:08 
AnswerRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
led mike4-Mar-09 5:41
led mike4-Mar-09 5:41 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
zkii4-Mar-09 17:54
zkii4-Mar-09 17:54 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
led mike5-Mar-09 5:28
led mike5-Mar-09 5:28 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
zkii5-Mar-09 17:02
zkii5-Mar-09 17:02 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
led mike6-Mar-09 5:47
led mike6-Mar-09 5:47 
QuestionStreamReader delimiters in C++/CLI Pin
J_E_D_I3-Mar-09 23:14
J_E_D_I3-Mar-09 23:14 
AnswerRe: StreamReader delimiters in C++/CLI Pin
ky_rerun5-Mar-09 7:50
ky_rerun5-Mar-09 7:50 

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.