예제 #1
0
파일: Task.cs 프로젝트: emret/AsyncSample
 protected virtual void OnMyTaskProgressChanged(MyTaskProgressChangedEventArgs e)
 {
     if (MyTaskProgressChanged != null)
         MyTaskProgressChanged(this, e);
 }
예제 #2
0
파일: Task.cs 프로젝트: emret/AsyncSample
        private void MyTaskWorker(string[] files, AsyncOperation async, MyAsyncContext asyncContext, out bool cancelled)
        {
            cancelled = false;

            for (int i = 0; i < files.Length; i++)
            {
                // a time consuming operation with a file (compression, encryption etc.)
                Thread.Sleep(1000);

                // compute progress
                int progressPercentage = 100 * (i + 1) / files.Length;

                // raise the progress changed event
                MyTaskProgressChangedEventArgs eArgs = new MyTaskProgressChangedEventArgs(progressPercentage, files[i], Id, null);
                async.Post(delegate(object e) { OnMyTaskProgressChanged((MyTaskProgressChangedEventArgs)e); }, eArgs);

                if (asyncContext.IsCancelling)
                {
                    cancelled = true;
                    return;
                }
            }
        }
예제 #3
0
 static void task_MyTaskProgressChanged(object sender, MyTaskProgressChangedEventArgs e)
 {
     Console.WriteLine("[MyTask][{2}] Progress: {0} %, Current file: {1}", e.ProgressPercentage, e.CurrentFile, e.Id);
 }