示例#1
0
        public void DoWork()
        {
            Console.WriteLine("Worker: work started");
            if (this.Started != null)
            {
                this.Started();
            }

            Console.WriteLine("Worker: work progressing");
            if (this.Progressing != null)
            {
                this.Progressing();
            }

            Console.WriteLine("Worker: work completed");
            if (this.Completed != null)
            {
                foreach (WorkCompleted wc in this.Completed.GetInvocationList())
                {
                    WorkCompleted wc2 = wc;
                    wc.BeginInvoke(delegate(IAsyncResult result)
                    {
                        int grade = wc2.EndInvoke(result);
                        Console.WriteLine("Worker grade= {0}", grade);
                    },
                                   null);
                }
            }
        }
        void WorkGraded(IAsyncResult res)
        {
            WorkCompleted wc    = (WorkCompleted)res.AsyncState;
            int           grade = wc.EndInvoke(res);

            Console.WriteLine("Worker grade = " + grade);
        }
示例#3
0
 /// <summary>
 ///     Used to invoke the <see cref="WorkCompleted" /> event
 /// </summary>
 /// <param name="args">The TCompletedArgs to send in the event</param>
 private void OnCompleted(TCompletedArgs args)
 {
     logger.Log(LogLevel.Information, this, string.Format("Worker completed at {0}", DateTime.Now));
     if (WorkCompleted != null)
     {
         WorkCompleted.BeginInvoke(this, args, iar => WorkCompleted.EndInvoke(iar), null);
     }
 }
示例#4
0
 /// <summary>
 ///     Used to invoke the <see cref="WorkCompleted" /> event
 /// </summary>
 /// <param name="args">The TCompletedArgs to send in the event</param>
 private void OnCompleted(TCompletedArgs args)
 {
     LogInformation("Worker completed at {0}", DateTime.Now);
     if (WorkCompleted != null)
     {
         WorkCompleted.BeginInvoke(this, args, iar => WorkCompleted.EndInvoke(iar), null);
     }
 }