Ejemplo n.º 1
0
        public static ThreadResults [] AsyncInvokeDelegates(Delegate method, ThreadResults.CallBackHandler preInvokeCallback, ThreadResults.CallBackHandler postInvokeCallback, params object[] pars)
        {
            //List<ThreadResults> rlt = new List<ThreadResults>();
            Delegate[]      dgs = method.GetInvocationList();
            ThreadResults[] rlt = new ThreadResults[dgs.Length];
            int             i   = 0;

            foreach (Delegate dg in dgs)
            {
                rlt[i] = AsyncInvokeSingleDelegate(dg, preInvokeCallback, postInvokeCallback, pars);
                i++;
            }
            return(rlt);
        }
Ejemplo n.º 2
0
        public static void AsyncInvokeSingleDelegate(Delegate method, ThreadResults.CallBackHandler preInvokeCallBack, ThreadResults.CallBackHandler postInvokeCallback, out ThreadResults returnVal, params object[] pars)
        {
            ThreadResults rlts = new ThreadResults();

            if (postInvokeCallback != null)
            {
                rlts.PostInvokeCallBack = postInvokeCallback;
            }
            if (preInvokeCallBack != null)
            {
                rlts.PreInvokeCallBack = preInvokeCallBack;
            }
            ParameterizedThreadStart pts = new ParameterizedThreadStart(delegate(object par)
            {
                ThreadResults tr = (ThreadResults)par;
                try
                {
                    tr.Add(method.DynamicInvoke(pars));
                    tr.IsEmpty = false;
                }
                catch (Exception err)
                {
                    Exceptions.LogOnly(err.InnerException);
                    tr.Err = err.InnerException;
                    throw (tr.Err);
                }
                finally
                {
                    tr.Target = method.Target;
                    if (tr.PostInvokeCallBack != null)
                    {
                        //tr.CallBack.DynamicInvoke(null);
                        tr.PostInvokeCallBack(method.Target, tr, pars);
                    }
                }
            });
            Thread th = new Thread(pts);

            th.SetApartmentState(ApartmentState.STA);
            rlts.Thread = th;
            if (rlts.PreInvokeCallBack != null)
            {
                rlts.PreInvokeCallBack(method.Target, rlts, pars);
            }
            th.Start(rlts);
            returnVal = rlts;
            //return returnVal;
        }