Page 1 of 1
.NET Remoting and Callbacks
Posted: 22 Mar 2012, 16:01
by hummerbaendiger
I'm currently working with the .NET remoting interface in an external C# program.
Can anyone give me a short sample on how to use the callback functions to connect functions of an external program to events invoked by Ventuz?
I knew this already was here somewhere in the forum, but I can't find it anymore.
Thank you!
Re: .NET Remoting and Callbacks
Posted: 27 Mar 2012, 09:07
by Karol
Hi!
With Ventuz Remoting 2 it would look like this:
Code: Select all
private void SetupEvents(IExternalCollection extColl)
{
if ( extColl != null )
{
// get Event names for subscribtion
IEnumerator<IExternal> extEnum = extColl.GetEnumerator();
while ( extEnum.MoveNext() )
{
IExternal ext = extEnum.Current;
// subscribe to externalized events
if ( ext is IExternalEvent )
{
((IExternalEvent)ext).Callback += new ExternalEventHandler(Event_Callback);
Console.WriteLine("-- Subscribed to Event {0}", ((IExternalEvent)ext).Name);
}
}
}
}
Use the Externals property on your RemoteScene instance to get the IExternalCollection.
See the Ventuz Remoting API Help for further details.
Best Regards
Karol
Re: .NET Remoting and Callbacks
Posted: 18 Apr 2014, 09:46
by divingeon
hi, Karol
While I was finding "CallBack" on this forum, I found your post.
btw,
((IExternalEvent)ext).Callback += new ExternalEventHandler(Event_Callback);
What is the "Event_Callback" above this code?
How can I Make it?
thanks
divin
Re: .NET Remoting and Callbacks
Posted: 22 Apr 2014, 09:31
by Karol
Hi!
'Event_Callback' is the callback method which is called if an event occurs :
Could be something like this:
Code: Select all
private void Event_Callback(IExternalEvent exernal, ulong time, int arg)
{
Console.WriteLine("-=# EVENT_CALLBACK #=-");
lock ( this.eventQ )
{
// fill Q. to process it in UpdateEvents()
this.eventQ.Enqueue(string.Format("Event #{0}: {1} - Args = {2}\r\n", ++evCount, exernal.Name, arg));
this.haveNewEvents = true;
}
if ( this.tbEvents.InvokeRequired )
{
// cross-thread: so invoke on GUI-Thread
this.tbEvents.Invoke(new UpdateEventText(this.UpdateEvents));
}
else
{
this.UpdateEvents();
}
}
Cheers
Karol
Re: .NET Remoting and Callbacks
Posted: 23 Apr 2014, 03:11
by divingeon
thanks a lot