Exemplo n.º 1
0
        internal static void DomainCallBack()
        {
            TaskInfo t          = (TaskInfo)AppDomain.CurrentDomain.GetData("TaskInfo");
            string   folderPath = AppDomain.CurrentDomain.GetData("DllFolderPath").ToString();

            AppDomain.CurrentDomain.SetData("APPBASE", folderPath);
            AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", Path.Combine(folderPath, "app.config"));
            AppDomainTaskExecutor handler = (AppDomainTaskExecutor)AppDomain.CurrentDomain.GetData("ExceptionHandler");

            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                if (e.ExceptionObject is System.Exception)
                {
                    Exception ex1  = (Exception)e.ExceptionObject;
                    string    desc = "AppDomain的UnhandledException事件被触发";
                    Logger.Error(new ExceptionEventArgs(ex1.ToString(), folderPath, t.ID, desc));
                    try
                    {
                        handler.OnUnhandledException(ex1.ToString(), desc);
                    }
                    catch (Exception ex2)
                    {
                        Logger.Error(folderPath, t.ID, ex2, "执行AppDomain.CurrentDomain.UnhandledException的OnUnhandledException时出错");
                    }
                }
            };
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                string path = args.Name.Split(',')[0].Trim() + ".dll";
                path = Path.Combine(AppDomain.CurrentDomain.GetData("DllFolderPath").ToString(), path);
                if (File.Exists(path))
                {
                    try
                    {
                        return(Assembly.LoadFrom(path));
                    }
                    catch (Exception ex)
                    {
                        var de = new ExceptionEventArgs(ex, folderPath, t.ID, "Failed to load assembly \"" + path + "\" in AppDomain.CurrentDomain.AssemblyResolve.");
                        Logger.Error(de);
                        try
                        {
                            handler.OnUnhandledException(de);
                        }
                        catch (Exception ex1)
                        {
                            Logger.Error(folderPath, t.ID, ex1, "执行AppDomain.CurrentDomain.AssemblyResolve的OnUnhandledException时出错");
                        }
                    }
                }
                return(null);
            };
            TaskExecutor executor = new TaskExecutor(folderPath, t);

            executor.UnhandledException += (s, e) =>
            {
                handler.OnUnhandledException(e);
            };
            executor.ExecutedNotify += (s, e) =>
            {
                handler.OnExecutedNotify(e);
            };
            AppDomain.CurrentDomain.SetData("Executor", executor);
        }
Exemplo n.º 2
0
 public void InitScheduler(TaskInfo task)
 {
     m_ScheduleList = task.ScheduleList;
 }
Exemplo n.º 3
0
 public AppDomainTaskExecutor(string folderPath, TaskInfo task)
 {
     m_FolderPath = folderPath;
     InitFromTask(task);
 }