.NET Remoting and Callbacks

Q and A about functionality and how to solve a special task for your application.

.NET Remoting and Callbacks

Postby hummerbaendiger » 22 Mar 2012, 16:01

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!
hummerbaendiger
 
Posts: 16
Joined: 22 Mar 2012, 15:54

Re: .NET Remoting and Callbacks

Postby Karol » 27 Mar 2012, 09:07

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
User avatar
Karol
 
Posts: 455
Joined: 10 Jan 2012, 12:07

Re: .NET Remoting and Callbacks

Postby divingeon » 18 Apr 2014, 09:46

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
divingeon
 
Posts: 5
Joined: 28 Mar 2012, 02:57

Re: .NET Remoting and Callbacks

Postby Karol » 22 Apr 2014, 09:31

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
User avatar
Karol
 
Posts: 455
Joined: 10 Jan 2012, 12:07

Re: .NET Remoting and Callbacks

Postby divingeon » 23 Apr 2014, 03:11

thanks a lot :)
divingeon
 
Posts: 5
Joined: 28 Mar 2012, 02:57


Return to How to...

cron