Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

.NET Remoting and Callbacks

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

Moderator: Support

Post Reply
hummerbaendiger
Posts: 21
Joined: 22 Mar 2012, 15:54

.NET Remoting and Callbacks

Post by 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!

User avatar
Karol
Posts: 640
Joined: 10 Jan 2012, 12:07

Re: .NET Remoting and Callbacks

Post by 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

divingeon

Re: .NET Remoting and Callbacks

Post by 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

User avatar
Karol
Posts: 640
Joined: 10 Jan 2012, 12:07

Re: .NET Remoting and Callbacks

Post by 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

divingeon

Re: .NET Remoting and Callbacks

Post by divingeon » 23 Apr 2014, 03:11

thanks a lot :)

Post Reply