コード例 #1
0
        /// <summary>
        /// Creates or loads the state for this task.
        /// </summary>
        /// <param name="task">The task to create or load state for.</param>
        /// <returns></returns>
        protected State GetState(ITask task)
        {
            State _state = null;
            Guid  taskId = Guid.Empty;

            // THREE-WAY DECISION:
            // 1) no ITask object--assume new Task, create new TaskID, create new State
            // 2) ITask object, but no valid TaskID--assume new Task, create new State
            // 3) ITask object, valid TaskID--assume known Task, retrieve known State
            //
            // CASE (1):
            // if incoming ITask is null, we KNOW this is a new Task. Act appropriately--create new Task/State
            if (null == task)
            {
                _state = CreateState();
                taskId = _state.TaskId;
            }
            else
            {
                // ask the incoming ITask if it has a TaskID already.
                // this would mean the application has already hooked up a Task ID to whatever representation it uses...
                // for example, correlating TaskID to windows logon

                taskId = task.Get();
                _state = GetState(taskId);

                if (Guid.Empty == taskId)
                {
                    // tell the taskObject (which is our sink back into client application) about the new TaskID
                    task.Create(_state.TaskId);
                }
            }

            return(_state);
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: JimFawcett/Interop
        //----< wrapper runs long task asynchronously >----------------------

        Task longTaskWrapper()
        {
            // create instance of native task

            ITask rTask = ITask.Create();

            // hook up callback if not done already

            if (rTask.callback == null)
            {
                rTask.callback = new ITask.EventCallBack(this.updateStatus);
            }

            // run task asynchronously

            Task task = Task.Run(() => rTask.run(Dispatcher));

            return(task);
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: JimFawcett/Interop
        //----< Run long task synchronously on UI thread >-------------------

        private void SynchButton_Click(object sender, RoutedEventArgs e)
        {
            disableButtons();

            // Force UI to update.  Without this buttons stay enabled.

            Dispatcher.Invoke(() => InvalidateVisual(), System.Windows.Threading.DispatcherPriority.Render);

            // create native task instance

            ITask rTask = ITask.Create();

            // no point in sending callbacks - UI thread isn't listening
            // rTask.callback = new ITask.EventCallBack(this.updateStatus);

            rTask.run(Dispatcher);

            // Refresh UI

            enableButtons();
        }
コード例 #4
0
 public void Create()
 {
     Task.Create();
 }