Exemplo n.º 1
0
        private void WaitForUnBind()
        {
            bool flag = Delegater.WaitTrue(() => Window.UnBind(), () => Window.Dm.Delay(1000), 10);

            if (!flag)
            {
                throw new Exception("窗口“{0}”解除绑定失败。".FormatWith(Window.Title));
            }
        }
Exemplo n.º 2
0
        private Thread GetWorkThread(IEnumerable <TaskBase> tasks)
        {
            return(new Thread(() =>
            {
                foreach (TaskBase task in tasks)
                {
                    _task = task;
                    _taskEventArg = new TaskEventArg {
                        Context = _task.TaskContext
                    };
                    try
                    {
                        //窗口绑定
                        DmPlugin dm = Window.Dm;
                        bool flag;
                        flag = Delegater.WaitTrue(() => Window.BindHalfBackground(), () => dm.Delay(1000), 10);
                        //flag = Delegater.WaitTrue(() => Window.BindNormal(), () => dm.Delay(1000), 10);
                        if (!flag)
                        {
                            throw new Exception("角色绑定失败,请添加杀软信任,右键以管理员身份运行,Win7系统请确保电脑账户为“Administrator”");
                        }
                        TaskRunState = TaskRunState.Running;
                        OnStateChanged(_taskEventArg);
                        OnStarted(_taskEventArg);
                        OutMessage("任务“{0}”启动成功。".FormatWith(_task.Name));

                        TaskStart();
                        TaskStop();
                        Window.FlashWindow();
                    }
                    catch (ThreadAbortException)
                    {
                        TaskStop(true);
                        WaitForUnBind();
                        break;
                    }
                    catch (Exception ex)
                    {
                        TaskStop();
                        Window.FlashWindow();
                        Logger.Error("任务执行失败,{0}", ex.FormatMessage());
                        OutMessage("任务执行失败,{0}".FormatWith(ex.Message));
                    }
                    Window.Dm.Delay(1000);
                    TaskList.Remove(task);
                }
                WaitForUnBind();
                _workThread = null;
            })
            {
                IsBackground = true
            });
        }
Exemplo n.º 3
0
        private Thread GetWorkThread(IEnumerable <TaskBase> tasks)
        {
            return(new Thread(() =>
            {
                //窗口绑定
                DmPlugin dm = Window.Dm;
                bool flag;
                flag = Delegater.WaitTrue(() => Window.BindHalfBackgroundMoniqi(), () => dm.Delay(1000), 10);
                if (!flag)
                {
                    throw new Exception("角色绑定失败,请添加杀软信任,右键以管理员身份运行,Win7系统请确保电脑账户为“Administrator”");
                }
                // dm.DownCpu(20);
                while (true)
                {
                    Cycle = 0;
                    if (AutoLogin != null)
                    {
                        bool isLogin = AutoLogin();
                        if (isLogin == false)
                        {
                            Logger.Error("任务执行失败,{0}", "登录失败!");
                            OutMessage("任务执行失败,{0}".FormatWith("登录失败!"));
                            break;
                        }
                    }
                    while (true)
                    {
                        Cycle++;
                        foreach (TaskBase task in tasks)
                        {
                            _task = task;
                            _taskEventArg = new TaskEventArg {
                                Context = _task.TaskContext
                            };
                            try
                            {
                                TaskRunState = TaskRunState.Running;
                                OnStateChanged(_taskEventArg);
                                OnStarted(_taskEventArg);

                                OutMessage("任务“{0}”启动成功。".FormatWith(_task.Name));
                                TaskStart();
                                TaskStop(true);
                                Window.FlashWindow();
                            }
                            catch (ThreadAbortException)
                            {
                                TaskStop(true);
                                WaitForUnBind();
                                break;
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                                TaskStop();
                                Window.FlashWindow();
                                Logger.Error("任务执行失败,{0}", ex.FormatMessage());
                                OutMessage("任务执行失败,{0}".FormatWith(ex.Message));
                            }
                            Window.Dm.Delay(1000);
                            TaskList.Remove(task);
                        }

                        //切换角色
                        if (ChangeRole != null)
                        {
                            bool isChange = ChangeRole();
                            if (isChange == false)
                            {
                                Logger.Error("切换角色失败!");
                                OutMessage("切换角色失败!");
                                if (AutoLogin != null)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            WaitForUnBind();
                            _workThread = null;
                            return;
                        }
                        Thread.Sleep(5000);
                    }
                    Thread.Sleep(5000);
                }
                WaitForUnBind();
                _workThread = null;
            })
            {
                IsBackground = true
            });
        }