Ejemplo n.º 1
0
		internal void FireEventToDelegates(MulticastDelegate md, ManagementEventArgs args)
		{
			try
			{
				if (md != null)
				{
					Delegate[] invocationList = md.GetInvocationList();
					for (int i = 0; i < (int)invocationList.Length; i++)
					{
						Delegate @delegate = invocationList[i];
						try
						{
							object[] objArray = new object[2];
							objArray[0] = this.sender;
							objArray[1] = args;
							@delegate.DynamicInvoke(objArray);
						}
						catch
						{
						}
					}
				}
			}
			catch
			{
			}
		}
Ejemplo n.º 2
0
 internal void FireEventToDelegates(MulticastDelegate md, ManagementEventArgs args)
 {
     try
     {
         if (md != null)
         {
             Delegate[] invocationList = md.GetInvocationList();
             for (int i = 0; i < (int)invocationList.Length; i++)
             {
                 Delegate @delegate = invocationList[i];
                 try
                 {
                     object[] objArray = new object[2];
                     objArray[0] = this.sender;
                     objArray[1] = args;
                     @delegate.DynamicInvoke(objArray);
                 }
                 catch
                 {
                 }
             }
         }
     }
     catch
     {
     }
 }
        /// <summary>
        /// Custom handler for firing a WMI event to a list of delegates. We use
        /// the process thread pool to handle the firing.
        /// </summary>
        /// <param name="md">The MulticastDelegate representing the collection
        /// of targets for the event</param>
        /// <param name="args">The accompanying event arguments</param>
        internal void FireEventToDelegates(MulticastDelegate md, ManagementEventArgs args)
        {
            try
            {
                if (null != md)
                {
#if USEPOOL
                    Delegate[] delegateList = md.GetInvocationList();

                    if (null != delegateList)
                    {
                        int numDelegates             = delegateList.Length;
                        AutoResetEvent[] waitHandles = new AutoResetEvent [numDelegates];

                        /*
                         * For each target delegate, queue a request to the
                         * thread pool to handle the POST. We pass as state the
                         *  1) Target delegate
                         *  2) Event args
                         *  3) AutoResetEvent that the thread should signal to
                         *     indicate that it is done.
                         */
                        for (int i = 0; i < numDelegates; i++)
                        {
                            waitHandles [i] = new AutoResetEvent(false);
                            ThreadPool.QueueUserWorkItem(
                                new WaitCallback(this.FireEventToDelegate),
                                new WmiEventState(delegateList[i], args, waitHandles[i]));
                        }

                        /*
                         * We wait for all the delegates to signal that they are done.
                         * This is because if we return from the IWbemObjectSink callback
                         * before they are all done, it is possible that a delegate will
                         * begin to process the next callback before the current callback
                         * processing is done.
                         */
                        WaitHandle.WaitAll(waitHandles, 10000, true);
                    }
                }
#endif
                    foreach (Delegate d in md.GetInvocationList())
                    {
                        try
                        {
                            d.DynamicInvoke(new object [] { this.sender, args });
                        }
                        catch
                        {
                        }
                    }
                }
            }
 internal void FireEventToDelegates(MulticastDelegate md, ManagementEventArgs args)
 {
     try
     {
         if (md != null)
         {
             foreach (Delegate delegate2 in md.GetInvocationList())
             {
                 try
                 {
                     delegate2.DynamicInvoke(new object[] { this.sender, args });
                 }
                 catch
                 {
                 }
             }
         }
     }
     catch
     {
     }
 }
 internal WmiEventState(System.Delegate d, ManagementEventArgs args, System.Threading.AutoResetEvent h)
 {
     this.d = d;
     this.args = args;
     this.h = h;
 }
Ejemplo n.º 6
0
		internal WmiEventState(Delegate d, ManagementEventArgs args, AutoResetEvent h)
		{
			this.d = d;
			this.args = args;
			this.h = h;
		}
 internal WmiEventState(Delegate d, ManagementEventArgs args, AutoResetEvent h)
 {
     this.d    = d;
     this.args = args;
     this.h    = h;
 }
        /// <summary>
        /// Custom handler for firing a WMI event to a list of delegates. We use
        /// the process thread pool to handle the firing.
        /// </summary>
        /// <param name="md">The MulticastDelegate representing the collection
        /// of targets for the event</param>
        /// <param name="args">The accompanying event arguments</param>
        internal void FireEventToDelegates (MulticastDelegate md, ManagementEventArgs args)
        {
            try 
            {
                if (null != md)
                {
#if USEPOOL
                    Delegate[] delegateList = md.GetInvocationList ();

                    if (null != delegateList)
                    {
                        int numDelegates = delegateList.Length;
                        AutoResetEvent[] waitHandles = new AutoResetEvent [numDelegates];

                        /*
                         * For each target delegate, queue a request to the 
                         * thread pool to handle the POST. We pass as state the 
                         *  1) Target delegate
                         *  2) Event args
                         *  3) AutoResetEvent that the thread should signal to 
                         *     indicate that it is done.
                         */
                        for (int i = 0; i < numDelegates; i++)
                        {
                            waitHandles [i] = new AutoResetEvent (false);
                            ThreadPool.QueueUserWorkItem (
                                    new WaitCallback (this.FireEventToDelegate),
                                    new WmiEventState (delegateList[i], args, waitHandles[i]));
                        }

                        /*
                         * We wait for all the delegates to signal that they are done.
                         * This is because if we return from the IWbemObjectSink callback
                         * before they are all done, it is possible that a delegate will
                         * begin to process the next callback before the current callback
                         * processing is done.
                         */
                        WaitHandle.WaitAll (waitHandles, 10000, true);
                        }
                    }
#endif
                    foreach (Delegate d in md.GetInvocationList())
                    {
                        try 
                        {
                            d.DynamicInvoke (new object [] {this.sender, args});    
                        } 
                        catch
                        {
                        }
                    }
                }
            }
 internal WmiEventState(System.Delegate d, ManagementEventArgs args, System.Threading.AutoResetEvent h)
 {
     this.d    = d;
     this.args = args;
     this.h    = h;
 }