QueueSystem.CancelJobSimple Method

Cancels the specified job in the Project Server Queuing Service.

Namespace:  WebSvcQueueSystem
Assembly:  ProjectServerWebServices (in ProjectServerWebServices.dll)


<SoapDocumentMethodAttribute("http://schemas.microsoft.com/office/project/server/webservices/QueueSystem/CancelJobSimple", RequestNamespace := "http://schemas.microsoft.com/office/project/server/webservices/QueueSystem/",  _
    ResponseNamespace := "http://schemas.microsoft.com/office/project/server/webservices/QueueSystem/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub CancelJobSimple ( _
    jobUID As Guid _
Dim instance As QueueSystem
Dim jobUID As Guid

[SoapDocumentMethodAttribute("http://schemas.microsoft.com/office/project/server/webservices/QueueSystem/CancelJobSimple", RequestNamespace = "http://schemas.microsoft.com/office/project/server/webservices/QueueSystem/", 
    ResponseNamespace = "http://schemas.microsoft.com/office/project/server/webservices/QueueSystem/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void CancelJobSimple(
    Guid jobUID



CancelJobSimple calls CancelJob with the parameters cancelCorrelationJobs = true and cancelSendIncompleteJobs = false.


There is a potential race condition between checking the state of a job and calling CancelJobSimple. When an application checks the state of a job, it might be ReadyForProcessing. Before calling CancelJobSimple, the state can switch to Processing or any other state.

Project Server Permissions




Manage the Project Server queue. Global permission.


The QueueSystemUtils class is described in How to: Use the QueueSystem Web Service.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Threading;

namespace SomeNamespace
    class QueueSystemUtils
        // Wait 2 seconds between each check for job completion.
        private const int INCREMENTALSLEEPTIME = 2; 

        public QueueSystemUtils()

        /// <summary>
        /// Wait a specified time for the Project Server Queuing service to process a job.
        /// </summary>
        /// <param name="q">QueueSystem object</param>
        /// <param name="timeOut">Maximum time to wait (seconds)</param>
        /// <param name="jobId">GUID of queue job</param>
        /// <param name="errorString">out: error from GetJobCompletionState plus status</param>
        /// <returns>true for success; false for any queue failure</returns>
        public bool WaitForQueue(WebSvcQueueSystem.QueueSystem q, 
            int timeOut, 
            Guid jobId, 
            out String statusOut)
            int wait;                 // Number of seconds to wait
            decimal seconds;          // for reporting wait time in decimal format.
            string xmlError;          // XML error output from the queue
            string queueStatus;       // Outer XML of xmlError string.
            string status = "";       // Summary status report for output.
            bool firstPass = true;    // First iteration through the while statement.
            int timeSlept = 0;        // Total time slept (seconds).
            bool jobIsDone = false;   // The queue job completed successfully, if true.
            bool stopWait = false;    // Abort the wait, if true.
            WebSvcQueueSystem.JobState jobState; // Status of the queue job. 

            while (true)
                // On the first iteration, wait the incremental sleep time  
                // or the maximum requested timeout. 
                if (firstPass)
                    // Get the estimated time to wait for the queue to process the job.
                    // The output from GetJobWaitTime is in seconds.
                    wait = q.GetJobWaitTime(jobId);

                    status = string.Format("Estimated job wait time: {0} seconds", wait);

                    if (timeOut < INCREMENTALSLEEPTIME) wait = timeOut;
                    else wait = INCREMENTALSLEEPTIME;

                    firstPass = false;
                    // If job is not done, wait the incremental sleep time.  
                    wait = INCREMENTALSLEEPTIME;

                Thread.Sleep(wait * 1000); // Milliseconds

                timeSlept += wait;

                // Check job state.
                jobState = q.GetJobCompletionState(jobId, out xmlError);

                // Add the XML error output to the status.
                StringReader sr = new StringReader(xmlError);
                using (XmlReader reader = XmlReader.Create(sr))
                    queueStatus = reader.ReadOuterXml();
                // Don't add an empty <errinfo> element.
                if (queueStatus != "<errinfo />") status += "\n\n" + queueStatus;

                if (jobState == WebSvcQueueSystem.JobState.Success)
                    jobIsDone = true;
                else if (jobState == WebSvcQueueSystem.JobState.Unknown
                    || jobState == WebSvcQueueSystem.JobState.Failed
                    || jobState == WebSvcQueueSystem.JobState.FailedNotBlocking
                    || jobState == WebSvcQueueSystem.JobState.CorrelationBlocked
                    || jobState == WebSvcQueueSystem.JobState.Canceled)
                    stopWait = true;

                if (!jobIsDone && timeSlept >= timeOut)
                    // Cancel the job, otherwise the queue keeps processing it until it is complete.
                    stopWait = true;
                    status += string.Format("\n\nExceeded timeout of {0} seconds", timeOut);

                if (jobIsDone || stopWait)
                    // Check jobState again, might be cancelled.
                    seconds = Convert.ToDecimal(timeSlept);
                    status += string.Format(
                        "\n\nJobState: {0:G}\n\nTotal time slept: {1:N} seconds", 
                        jobState, seconds);
            statusOut = status;
            return jobIsDone;

See Also


QueueSystem Class

QueueSystem Members

WebSvcQueueSystem Namespace