コード例 #1
0
        /// <summary>
        /// Starts running the task asynchronously on another thread.
        /// </summary>
        /// <param name="taskData">Task-specific data to be supplied to the task.</param>
        /// <param name="doWork">The function that executes the asynchronous task.</param>
        /// <param name="onWorkComplete">The function to call when the task ends.</param>
        /// <remarks>This function will cause the application-wide progress indicator to appear after a small delay.</remarks>
        public void RunTask(AsyncTaskData taskData, Action<AsyncTaskData> doWork, Action<AsyncTaskData> onWorkComplete)
        {
#if MAC
            INTV.Shared.ComponentModel.CommandManager.InvalidateRequerySuggested();
#endif // MAC
            if (_showsProgress && (_progressIndicator != null))
            {
                _didShowProgresss = _progressIndicator.IsVisible;
                _progressIndicator.PropertyChanged += OnProgressIndicatorPropertyChanged;
                _progressIndicator.Show(this);
            }
            _taskData = taskData;
            _taskData.Task = this;
            _doWork = doWork;
            _workComplete = onWorkComplete;
#if USE_ASYNC
            _backgroundWorker.RunWorkerAsync(taskData);
#else
            IsBusy = true;
            doWork(taskData);
            onWorkComplete(taskData);
            IsBusy = false;
#endif // USE_ASYNC
        }