Exemple #1
0
        private static List <MethodInfo> GetMethods(DefaultWorker worker)
        {
            List <MethodInfo> result = new List <MethodInfo>();

            var methods = worker.GetType().GetMethods();

            foreach (var method in methods)
            {
                if (method.ReturnType == worker.GetType())
                {
                    result.Add(method);
                }
            }

            return(result);
        }
Exemple #2
0
        private static void WorkerStart(DefaultWorker worker)
        {
            Thread.CurrentThread.Priority = ThreadPriority.Highest;

            Program.MainWnd.Working = true;

            var  methods       = GetMethods(worker).ToArray();
            bool errorHappened = false;

            Prepare();

            for (int i = 0; i < methods.Length; i++)
            {
                Program.MainWnd.SetProgressFromValues(i + 1, methods.Length);
                Program.MainWnd.SetStatus(GetFriendlyName(methods[i].Name));

                try
                {
                    worker.Check();

                    methods[i].Invoke(worker, new object[] { });
                }
                catch (TargetInvocationException ex)
                {
                    ErrorHandler(ex.InnerException);
                    errorHappened = true;

                    break;
                }
            }

            if (!errorHappened)
            {
                Done();
            }

            Program.MainWnd.SetProgress(0);
            Program.MainWnd.SetStatus("Ready!");

            Program.MainWnd.Working = false;
        }