/// <summary> /// The background task is first invoked here in the standard Run method /// </summary> /// <param name="taskInstance">This contains the TriggerDetails object, which is actually Windows.Graphics.Printing.Workflow.WorkflowTriggerDetails</param> public void Run(IBackgroundTaskInstance taskInstance) { // Take out a deferral here and complete once all the callbacks are done runDeferral = taskInstance.GetDeferral(); // Associate a cancellation handler with the background task. DisableAppxManifestItemPackageContentValidation taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled); try { PrintWorkflowTriggerDetails workflowTriggerDetails = taskInstance.TriggerDetails as PrintWorkflowTriggerDetails; // Get the activation arguments PrintWorkflowBackgroundSession sessionManager = workflowTriggerDetails.PrintWorkflowSession; // The workflow details object has the workflow session manager, // which is unique to this print job and use it to add the event handler callback routines sessionManager.SetupRequested += OnSetupRequested; // XPS OM printing scenario sessionManager.Submitted += OnXpsOMPrintSubmitted; // Tell the event source that it can start sessionManager.Start(); } finally { // Do something, like logging } }
/// <summary> /// The background task is first invoked here in the standard Run method /// </summary> /// <param name="taskInstance">This contains the TriggerDetails object, which is actually Windows.Graphics.Printing.Workflow.WorkflowTriggerDetails</param> public void Run(IBackgroundTaskInstance taskInstance) { // Take out a deferral here and complete once all the callbacks are done runDeferral = taskInstance.GetDeferral(); if (1 == System.Threading.Interlocked.Increment(ref TaskRefCount)) { AllTasksDoneEvent.Reset(); } // Associate a cancellation handler with the background task. taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled); try { PrintWorkflowTriggerDetails workflowTriggerDetails = taskInstance.TriggerDetails as PrintWorkflowTriggerDetails; // Get the activation arguments PrintWorkflowBackgroundSession sessionManager = workflowTriggerDetails.PrintWorkflowSession; // The workflow details object has the workflow session manager, // which is unique to this print job and use it to add the event handler callback routines sessionManager.SetupRequested += OnSetupRequested; // XPS OM printing scenario // sessionManager.Submitted += OnXpsOMPrintSubmitted; sessionManager.Submitted += OnXpsOMPrintSubmittedAsync; // Tell the event source that it can start // This call blocks until all the workflow callbacks complete sessionManager.Start(); } finally { // At this point, all of the callbacks have completed, so it's safe // to decrement the workflow task ref count and possibly signal the // application that it's safe to suspend. if (0 == System.Threading.Interlocked.Decrement(ref TaskRefCount)) { AllTasksDoneEvent.Set(); } } }