Exemple #1
0
        public void Raise()
        {
            //Initialize MyEventArgs object with some random value
            MyEventArgs eventArgs = new MyEventArgs(33);

            //Create list of exception
            List <Exception> exceptions = new List <Exception>();

            //Invoke OnChange Action by iterating on all subscribers event handlers
            foreach (Delegate handler in OnChange.GetInvocationList())
            {
                try
                {
                    //pass sender object and eventArgs while
                    handler.DynamicInvoke(this, eventArgs);
                }
                catch (Exception e)
                {
                    //Add exception in exception list if occured any
                    exceptions.Add(e);
                }
            }

            //Check if any exception occured while
            //invoking the subscribers event handlers
            if (exceptions.Any())
            {
                //Throw aggregate exception of all exceptions
                //occured while invoking subscribers event handlers
                throw new AggregateException(exceptions);
            }
        }
Exemple #2
0
 public void Dispose()
 {
     StopSensing();
     foreach (var d in OnChange.GetInvocationList())
     {
         OnChange -= d as SensorEventHandler;
     }
 }
 public void UnsubscribeAllHandlers()
 {
     if (OnChange != null)
     {
         foreach (System.Delegate d in OnChange.GetInvocationList())
         {
             OnChange -= (d as ObjChangedHandler);
         }
     }
 }     //end method
Exemple #4
0
 protected void fireOnChange(object value)
 {
     if (OnChange != null)
     {
         foreach (PropertyChangeDelegate pcd in OnChange.GetInvocationList())
         {
             pcd(Name, InternalType, value);
         }
     }
 }
 public void Raise()
 {
     foreach (Delegate h in OnChange.GetInvocationList())
     {
         try{
             h.DynamicInvoke(this.name);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.StackTrace);
         }
     }
 }
Exemple #6
0
            public void Raise()
            {
                var exceptions = new List <Exception>();

                foreach (Delegate handelr in OnChange.GetInvocationList())
                {
                    try
                    {
                        handelr.DynamicInvoke(this, EventArgs.Empty);
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ex);
                    }
                }
            }
            public void Raise()
            {
                var exceptions = new List <Exception>();

                foreach (var handler in OnChange.GetInvocationList())
                {
                    try {
                        handler.DynamicInvoke("self", EventArgs.Empty);
                    } catch (Exception ex) {
                        exceptions.Add(ex);
                    }
                }
                if (exceptions.Any())
                {
                    throw new AggregateException(exceptions);
                }
            }
Exemple #8
0
 protected void SendOnChange(float value)
 {
     if (null != OnChange)
     {
         foreach (EventHandler <ChangeEventArgs <float> > eh in OnChange.GetInvocationList())
         {
             try
             {
                 ChangeEventArgs <float> args = new ChangeEventArgs <float>(value);
                 OnChange(this, args);
             }
             catch (Exception e)
             {
                 Log.postException(e);
             }
         }
     }
 }
Exemple #9
0
            public void Raise()
            {
                var exceptions = new List <Exception>();
                int i          = 1;

                foreach (Delegate handler in OnChange.GetInvocationList())
                {
                    try
                    {
                        handler.DynamicInvoke(this, new MyArgs(i++));
                    }
                    catch (Exception e)
                    {
                        exceptions.Add(e);
                        Console.WriteLine("Error here {0}", e);
                    }
                }
            }
        public void ManuallyRaise()
        {
            var exceptions = new List <Exception>();

            foreach (Delegate handler in OnChange.GetInvocationList())
            {
                try
                {
                    handler.DynamicInvoke(this, new MyArgs(77));
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }
            }
            if (exceptions.Any())
            {
                throw new AggregateException(exceptions);
            }
        }
Exemple #11
0
        public void Raise()
        {
            var exceptions = new List <Exception>();

            foreach (Delegate handler in OnChange.GetInvocationList())
            {
                try
                {
                    handler.DynamicInvoke(this, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }
            }
            if (exceptions.Count > 0)
            {
                throw new Exception($"{exceptions.Count} exception happened");
            }
        }
Exemple #12
0
            public void Raise()                                            // in event raise function, provide error handling code
            {
                var exceptions = new List <Exception>();                   // add all exceptions into this exceptions list

                foreach (Delegate handler in OnChange.GetInvocationList()) // GetInvocationList() returns an array of delegates representing the invocation list of the current delegate.
                {
                    try
                    {
                        handler.DynamicInvoke(this, EventArgs.Empty); // invoke the method of current delegate
                    }
                    catch (Exception ex)                              // catch all exceptions and added to the list
                    {
                        exceptions.Add(ex);
                    }
                }

                if (exceptions.Any())                         // if the exception list is not empty, throw exception
                {
                    throw new AggregateException(exceptions); // throw the list to main
                }
            }
            public void Raise()
            {
                var exceptions = new List <Exception>();

                foreach (Delegate del in OnChange.GetInvocationList())
                {
                    try
                    {
                        del.DynamicInvoke(this, EventArgs.Empty);
                    }
                    catch (Exception e)
                    {
                        exceptions.Add(e);
                    }
                }

                if (exceptions.Any())
                {
                    throw new AggregateException(exceptions);
                }
            }
        public void Raise()
        {
            var exList = new List <Exception>();

            foreach (var del in OnChange.GetInvocationList())
            {
                try
                {
                    del.DynamicInvoke();
                }
                catch (Exception ex)
                {
                    exList.Add(ex);
                }
            }

            if (exList.Any())
            {
                throw new AggregateException(exList);
            }
        }
Exemple #15
0
            public void Raise()
            {
                var exceptions = new List <Exception>();

                foreach (var handler in OnChange.GetInvocationList())
                {
                    try
                    {
                        handler.DynamicInvoke(this, null);
                    }
                    catch (Exception e)
                    {
                        exceptions.Add(e);
                    }
                }

                if (exceptions.Any())
                {
                    throw new AggregateException(exceptions);
                }
            }
            public void Raise()
            {
                var exceptions = new List <Exception>();

                foreach (Delegate handler in OnChange.GetInvocationList())
                {
                    try
                    {
                        // By handling the exception each time, ensure that all subscribers are notified, even if an exception is thrown.
                        handler.DynamicInvoke(this, EventArgs.Empty);
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ex);
                    }
                }

                if (exceptions.Any())
                {
                    throw new AggregateException(exceptions);
                }
            }
            public void Raise()
            {
                MyEventArgs eventArgs = new MyEventArgs(1);

                List <Exception> exceptions = new List <Exception>();

                foreach (Delegate handler in OnChange.GetInvocationList())
                {
                    try
                    {
                        handler.DynamicInvoke(this, eventArgs);
                    }
                    catch (Exception e)
                    {
                        exceptions.Add(e);
                    }
                }

                if (exceptions.Any())
                {
                    throw new AggregateException(exceptions);
                }
            }
            public void Raise()
            {
                var exceptions = new List <Exception>();

                foreach (Delegate handler in OnChange.GetInvocationList())
                {
                    try
                    {
                        //Invoke the subscribe Event Handler
                        handler.DynamicInvoke(this, EventArgs.Empty);
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ex);
                    }
                }

                //This Any method is an extension method that requires the System.Linq library
                if (exceptions.Any())
                {
                    //Throw an exception if there are any
                    throw new AggregateException(exceptions);
                }
            }
Exemple #19
0
        public void Raise()
        {
            Console.WriteLine($"Invocation list: {OnChange.GetInvocationList().GetLength(0)}");
            //OnChange(this, EventArgs.Empty);

            var exceptions = new List <Exception>();

            foreach (Delegate handler in OnChange.GetInvocationList())
            {
                try
                {
                    handler.DynamicInvoke(this, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }
            }

            if (exceptions.Any())
            {
                throw new AggregateException(exceptions);
            }
        }