Пример #1
0
        /// <summary>
        /// 开启异常处理
        /// </summary>
        public static void StartExceptionHandler(HandlerItem <T> item)
        {
            TaskExceptionHandler <T> handlerObj = null;

            if (item.exceptionHandlerTarget == "Default")
            {
                handlerObj = new DefaultExceptionHandler <T>();
            }
            else
            {
                try
                {
                    handlerObj = (TaskExceptionHandler <T>)Activator.CreateInstance(item.exceptionHandlerTargetType);
                }
                catch
                {
                    handlerObj = new DefaultExceptionHandler <T>();
                }
            }
            handlerObj.AddExceptionTaskItem(item);
            handlerObj.Handler();
        }
Пример #2
0
 /// <summary>
 /// 线程工作方法
 /// </summary>
 private void Work()
 {
     while (work)
     {
         try
         {
             locks.WaitOne();//阻塞当前线程
             if (threadListen != null)
             {
                 threadListen.BeforeExcuting(contextObj.contextObj);
             }
             contextObj.taskItemObj(contextObj.contextObj);
             if (contextObj.backAction != null)
             {
                 contextObj.backAction(contextObj.contextObj);
             }
             if (threadListen != null)
             {
                 threadListen.AfterExcuted(contextObj.contextObj);
             }
         }
         catch (Exception ex)
         {
             if (threadListen != null)
             {
                 threadListen.ExceptionExcute(contextObj.contextObj, ex);
             }
             //执行异常操作
             TaskExceptionHandler <T> .StartExceptionHandler(contextObj);
         }
         finally
         {
             WorkComplete(this);
         }
     }
 }