Example #1
0
        public static async Task Run()
        {
            var ae = new AsyncEvent <int>(12);

            await ae.Subscribe(_owner, OnAeChanged1);

            Console.WriteLine("Subscribe 1");

            await ae.Subscribe(_owner, OnAeChanged2);

            Console.WriteLine("Subscribe 2");

            await ae.Subscribe(_owner, OnAeChanged3);

            Console.WriteLine("Subscribe 3");

            await ae.Invoke(13);

            await ae.Unsubscribe(_owner, OnAeChanged1);

            Console.WriteLine("Unubscribe 1");

            await ae.Invoke(14);

            await ae.Unsubscribe(_owner);

            Console.WriteLine("Unubscribe owner");

            await ae.Invoke(15);
        }
        /// <summary>
        /// This method is called from a WebRTC thread from <see cref="UWCController"/>.
        /// Uses <see cref="UnityToolbag.Dispatcher.InvokeAsync()"/>
        /// to wait for Unitys main thread to be ready before posting events.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="data">Converted input data from client.</param>
        public static void TriggerEvent(NetworkEventType eventType, InputDataHolder data)
        {
            AsyncEvent thisEvent = null;

            if (instance.eventDictionary.TryGetValue(eventType, out thisEvent))
            {
                Dispatcher.InvokeAsync(() =>
                {
                    thisEvent.Invoke(data);
                });
            }
        }
Example #3
0
 public Service()
 {
     Task.Factory.StartNew(async() =>
     {
         var rnd = new Random();
         var i   = 0;
         while (true)
         {
             i++;
             await Task.Delay(rnd.Next(100, 1000));
             var t = Changed.Invoke(i);
         }
     });
 }
 public async Task RaiseEvents()
 {
     Event?.Invoke(new TestEvent());
     await(AsyncEvent?.Invoke(new TestEvent()) ?? Task.CompletedTask);
 }