Exemplo n.º 1
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            FormWorkerJobArgument o  = (FormWorkerJobArgument)e.Argument;
            MethodInfo            mi = null;

            try
            {
                Type type = null;
                if (o.invoker is Type)
                {
                    type = (Type)o.invoker;
                }
                else
                {
                    type = o.invoker.GetType();
                }
                mi = type.GetMethod(o.name, new Type[] { typeof(WorkerState), typeof(Object) });
            }
            catch (Exception ex)
            {
                serr.println(typeof(FormWorker) + ".startWork; ex=" + ex);
            }
            if (mi != null)
            {
                try
                {
                    mi.Invoke(o.invoker, new object[] { o.state, o.arguments });
                }
                catch (Exception ex)
                {
                    serr.println(typeof(FormWorker) + ".startWork; ex=" + ex);
                }
            }
        }
Exemplo n.º 2
0
        public void workerProgressChanged(int index, int percentage)
        {
            ProgressBarWithLabel label = mLabels[index];

            if (label != null)
            {
                label.setProgress(percentage);
            }
            int    size      = mArguments.Count;
            double total     = 0.0;
            double processed = 0.0;

            for (int i = 0; i < size; i++)
            {
                FormWorkerJobArgument arg = mArguments[i];
                total += arg.state.getJobAmount();
                if (i < index)
                {
                    processed += arg.state.getJobAmount();
                }
                else if (i == index)
                {
                    processed += arg.state.getProcessedAmount();
                }
            }
            ptrUi.setTotalProgress((int)(processed / total * 100.0));
            ptrUi.Refresh();
        }
Exemplo n.º 3
0
        /// <summary>
        /// ジョブを追加します.objで指定したオブジェクトの,名前がnameであるメソッドを呼び出します.
        /// 当該メソッドは,戻り値は任意,引数は( WorkerState, Object )である必要があります.
        /// また,当該メソッドは第一引数で渡されたWorkerStateのインスタンスのisCancelRequestedメソッドを
        /// 監視し,その戻り値がtrueの場合速やかに処理を中止しなければなりません.その際,処理の中止後にreportCompleteの呼び出しを
        /// 行ってはいけません.
        /// </summary>
        /// <param name="obj">メソッドの呼び出し元となるオブジェクト</param>
        /// <param name="method_name">メソッドの名前</param>
        /// <param name="job_description">ジョブの概要</param>
        /// <param name="job_amount">ジョブの処理量を表す,何らかの量.</param>
        /// <param name="argument">メソッドの第二引数</param>
        public void addJob(Object obj, string method_name, string job_description, double job_amount, Object argument)
        {
            // プログレスバーのUIを作成
            ProgressBarWithLabelUi ui    = new ProgressBarWithLabelUi();
            ProgressBarWithLabel   label = new ProgressBarWithLabel();

            label.setupUi(ui);
            label.setText(job_description);
            // フォームのビューにUIを追加
            ptrUi.addProgressBar(ui);

            // ラベルのリストに登録
            int index = mLabels.Count;

            mLabels.Add(label);
            mMemManager.add(label);

            // スレッドを作成して起動(platform依存)
            FormWorkerJobArgument arg = new FormWorkerJobArgument();

            arg.invoker   = obj;
            arg.name      = method_name;
            arg.arguments = argument;
            arg.index     = index;
            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress = true;
            worker.DoWork             += new DoWorkEventHandler(worker_DoWork);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.ProgressChanged    += new ProgressChangedEventHandler(worker_ProgressChanged);
            mThreads.Add(worker);

            arg.state = new FormWorkerJobStateImp(worker, job_amount);
            mArguments.Add(arg);
        }
Exemplo n.º 4
0
        /// <summary>
        /// ジョブをキャンセルします(非同期)
        /// </summary>
        public void cancelJobSlot()
        {
            int size = mArguments.Count;

            for (int i = 0; i < size; i++)
            {
                FormWorkerJobArgument arg = mArguments[i];
                arg.state.requestCancel();
            }
        }
 public void AddWork(int ID, FormWorkerJobArgument jobarg)
 {
     IDTable.Add(ID);
     ArgsTable.Add(jobarg);
     StateTable.Add(jobarg.state);
 }
Exemplo n.º 6
0
        private void startWorker(int index)
        {
            FormWorkerJobArgument arg = mArguments[index];

            mThreads[index].RunWorkerAsync(arg);
        }