ArcGIS API for Silverlight - Library Reference
CancelJobStatusUpdates Method
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client.Printing Namespace > PrintTask Class : CancelJobStatusUpdates Method

jobId
The job id.
Cancels the job status updates such that the StatusUpdated and JobCompleted Events stops firing.

Syntax

Visual Basic (Declaration) 
Public Sub CancelJobStatusUpdates( _
   ByVal jobId As String _
) 
C# 
public void CancelJobStatusUpdates( 
   string jobId
)

Remarks

Invoking the CancelJobStatusUpdates Method immediately terminates the PrintTask.StatusUpdated and PrintTask.JobCompleted Events from firing for a particular ESRI.ArcGIS.Client.Tasks.JobInfo.JobId. However, the PrintTask job itself has not terminated on the ArcGIS Server. See the following diagram for the visual representation of the 'asynchronous geoprocessing task' flow:

Diagram of the 'asynchronous geoprocessing task' flow.

A common work flow for calling the CancelJobStatusUpdates Method might be a really long PrintTask job where the user needs to close out of the application before the job completes. If the JobId was stored on disk or saved via some other mechanism, the image could still be retrieved via the ESRI.ArcGIS.Client.Tasks.Geoprocessor Class. See the code example in this document for an example of using the Geoprocessor to obtain the image generated on ArcGIS Server as a result of an 'asynchronous geoprocessing task' using the PrintTask where the CancelJobStatusUpdates was used.

Parameters

jobId
The job id.

Example

How to use:

When the application loads, enter a correct Url to an ArcGIS Server PrintTask based on an 'asynchronous geoprocessing task'. Then click the 'SubmitJobAsync|CancelJobStatusUpdates' button (this will start a Print Task, obtain a JobID, and cancel all Job Status Updates from occuring). Then click the 'Get Job via Geoprocessor' to obtain the image started by the PrintTask via the Geoprocessor.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Showing how once a PrintTask.CancelJobStatusUpdates has been issued that the image can be returned via the Geoprocessor Class.

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="14,368,0,0" 
            Name="MyMap" VerticalAlignment="Top" WrapAround="True" Height="222" Width="600"
            Extent="-14130480,2889032,-7273626,6317460">
    <esri:Map.Layers>
      <esri:LayerCollection>
      
        <!-- Add a layer to the Map Control. -->
        <esri:ArcGISDynamicMapServiceLayer ID="MyArcGISDynamicMapServiceLayer"
          Url="http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_1990-2000_Population_Change/MapServer"/>
        
      </esri:LayerCollection>
    </esri:Map.Layers>
  </esri:Map>
  
  <!-- Url -->
  <sdk:Label Height="20" HorizontalAlignment="Left" Margin="8,100,0,0" Name="Label_Url" 
             VerticalAlignment="Top" Width="31" Content="Url:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="8,118,0,0" Name="TextBox_Url" 
           VerticalAlignment="Top" Width="605" FontSize="10" />
  
  <!-- Buttons to perform the work. -->
  <Button Content="SubmitJobAsync|CancelJobStatusUpdates" Height="72" HorizontalAlignment="Left" Margin="8,162,0,0" 
          Name="Button_SubmitJobAsync" VerticalAlignment="Top" Width="253" Click="Button_SubmitJobAsync_Click" IsEnabled="True"/>
  <Button Content="Get Job via Geoprocessor" Height="71" Width="253" HorizontalAlignment="Left" Margin="8,242,0,0" 
          Name="Button_GeoProcessor" VerticalAlignment="Top" Click="Button_GeoProcessor_Click" IsEnabled="False"/>
  
  <!-- JobInfo -->
  <sdk:Label Height="16" HorizontalAlignment="Left" Margin="13,328,0,0" Name="Label_JobId" VerticalAlignment="Top" 
             Width="35" Content="JobId:"/>
  <TextBlock Height="16" HorizontalAlignment="Left" Margin="14,346,0,0" Name="TextBlock_JobId" 
             VerticalAlignment="Top" Width="247" />
            
  <!-- Informational Messages -->
  <sdk:Label Height="21" HorizontalAlignment="Left" Margin="267,147,0,0" Name="Label_InfoMessage" 
             VerticalAlignment="Top" Width="169" Content="Informatonal Messages:"/>
  <ListBox Height="200" HorizontalAlignment="Left" Margin="267,162,0,0" Name="ListBox_InfoMessage" 
           VerticalAlignment="Top" Width="346" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="91" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="625" 
     TextWrapping="Wrap" Text="When the application loads, enter a correct Url to an ArcGIS Server PrintTask 
      based on an 'asynchronous geoprocessing task'. Then click the 'SubmitJobAsync|CancelJobStatusUpdates' 
      button (this will start a Print Task, obtain a JobID, and cancel all Job Status Updates from occuring). 
      Then click the 'Get Job via Geoprocessor' to obtain the image started by the PrintTask via the 
      Geoprocessor." />
      
</Grid>
C#Copy Code
// Create Global (aka. Member) variables for the PrintTask and Geoprocessor objects that will be 
// used in other parts of the application.
private ESRI.ArcGIS.Client.Printing.PrintTask _PrintTask;
private ESRI.ArcGIS.Client.Tasks.Geoprocessor _Geoprocessor;
            
public MainPage()
{
  InitializeComponent();
  
  // Provide a valid PrintTask.Url for a "asynchronous geoprocessing task"
  TextBox_Url.Text = "http://localhost:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export20Web20Map%20Task";
  
  // Set the _PrintTask variable to a new instance of the PrintTask Class.
  _PrintTask = new ESRI.ArcGIS.Client.Printing.PrintTask();
  
  // Prevent the internet browser from using a cache for the PrintTask operations.
  _PrintTask.DisableClientCaching = true;
  
  // Set the PrintTask.Url from what is entered in the TextBox.
  _PrintTask.Url = TextBox_Url.Text;
  
  // Wire up an Event Handler for the PrintTask.StatusUpdated Event.
  _PrintTask.StatusUpdated += printTask_StatusUpdated;
  
  // Set the _Geoprocessor variable to a new instance of the Geoprocessor Class.
  _Geoprocessor = new ESRI.ArcGIS.Client.Tasks.Geoprocessor();
  
  // Set the Geoprocessor.Url from what is entered in the TextBox.
  _Geoprocessor.Url = TextBox_Url.Text;
  
  // Wire up an Event Handler for the Geoprocessor.StatusUpdated Event.
  _Geoprocessor.StatusUpdated += geoprocessor_StatusUpdated;
  
  // Wire up an Event Handler for the Geoprocessor.GetResultDataCompleted Event.
  _Geoprocessor.GetResultDataCompleted += geoprocessor_GetResultDataCompleted;
}
            
private void Button_SubmitJobAsync_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Define the settings for rendering the image/.pdf on the ArcGIS Server.
  
  // Define the ExportOptions.
  ESRI.ArcGIS.Client.Printing.ExportOptions myExportOptions = new ESRI.ArcGIS.Client.Printing.ExportOptions();
  myExportOptions.Dpi = 96; //96 DPI is typical Window OS setting.
  myExportOptions.OutputSize = new Size(MyMap.ActualWidth, MyMap.ActualHeight); // Use the dimensions of the Map
  
  // Define the PrintParameters. 
  ESRI.ArcGIS.Client.Printing.PrintParameters myPrintParameters = new ESRI.ArcGIS.Client.Printing.PrintParameters(MyMap);
  myPrintParameters.ExportOptions = myExportOptions; // Use the ExportOptions defined earlier.
  myPrintParameters.LayoutTemplate = "MAP_ONLY"; // Look to the REST service to see what layout templates are supported.
  myPrintParameters.Format = "PNG32"; // Look to the REST service to see what image formats are supported.
  
  // Submit the 'PrintTask based asynchronous geoprocessing task' to ArcGIS Server. 
  _PrintTask.SubmitJobAsync(myPrintParameters);
  
  // Enable the Button for the user to retieve the ArcGIS Server exported image/.pdf via the Geoprocessor.
  Button_GeoProcessor.IsEnabled = true;
  
  // Display an informational message.
  ListBox_InfoMessage.Items.Add("The PrintTask to generate the image was started.");
}
            
private void printTask_StatusUpdated(object sender, ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs e)
{
  // Use only for SubmitJobAsync operations (i.e. asynchronous geoprocessing tasks).
  
  // This Event fires as a result of the PrintTask.SumbitJobAsync Method being used previously. It 
  // can fire multiple times depending on the state of the geoprocessing task executing.
  
  // Clear out the TextBlock any existing JobInfo messages.
  TextBlock_JobId.Text = "";
  
  // Get the JobInfo information messages.
  ESRI.ArcGIS.Client.Tasks.JobInfo myJobInfo = e.JobInfo;
  string myJobId = myJobInfo.JobId;
  
  // Display the JobInfo messages to the user.
  TextBlock_JobId.Text = myJobId;
  
  // Display an informational message.
  ListBox_InfoMessage.Items.Add("The PrintTask JobId was obtained.");
  
  // As soon as we get our first update on the Job in this Event, call the PrintTask.CancelJobStatusUpdates 
  // which will kill all future PrintTask.StatusUpdated Events (i.e. this Event) from firing. NOTE: the actual
  // PrintTask job is still submitted to the ArcGIS Server geoprocessor and is running/completed.
  _PrintTask.CancelJobStatusUpdates(TextBlock_JobId.Text);
  
  // Display some informational messages.
  ListBox_InfoMessage.Items.Add("All PrintTask messages have now been canceled.");
  ListBox_InfoMessage.Items.Add("And yet the ArcGIS Server PrintTask is still running.");
  ListBox_InfoMessage.Items.Add("Click the 'Get Job via Geoprocessor' to retrive the image.");
}
            
private void Button_GeoProcessor_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // We can no longer use the PrintTask Class to find out information about the "asynchronous geoprocessing task"
  // that was submitted via the PrintTask.SubmitJobAsync() Method because the PrintTask.CancelJobStatusUpdates was 
  // issued. We now need to use the Geoprocessor Class to find out information about the job by supplying the JobId 
  // obtained in the last PrintTask.StatusUpdated Event.
  // A common work flow for this type of situation might be a really long PrintTask job where the user needs to 
  // close out of the application before the job completes. If the JobId was stored on disk or saved via some other
  // mechanism, the image could still be retrieved via the Geoprocessor Class.
  _Geoprocessor.CheckJobStatusAsync(TextBlock_JobId.Text);
}
            
private void geoprocessor_StatusUpdated(object sender, ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs e)
{
  // This Event fires as a result of the Geoprocessor.CheckJobStatusAsync Method call.
  
  // Get the JobInfo.
  ESRI.ArcGIS.Client.Tasks.JobInfo myJobInfo = e.JobInfo;
  
  // Ensure we have valid results.
  if (myJobInfo != null)
  {
    // Get the JobStatus from the JobInfo.
    ESRI.ArcGIS.Client.Tasks.esriJobStatus myJobStatus = myJobInfo.JobStatus;
    
    // The PrintTask operation that generates the image completed.
    if (myJobStatus == ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobSucceeded)
    {
      // Display an informational message.
      ListBox_InfoMessage.Items.Add("The image file was found via the Geoprocessor.");
      
      // Invoke the Geoprocessor.GetResultDataAsync Method so we can retrieve the image.
      // The string parameter "Output_File" was obtained from the 'ArcGIS REST Service Directory' 
      // for the Url of the PrintTask and Geoprocessor services. Look for the 'Parameter' that is 
      // of 'Direction' esriGPParameterDirectionOutput.
      _Geoprocessor.GetResultDataAsync(TextBlock_JobId.Text, "Output_File");
    }
  }
}
            
private void geoprocessor_GetResultDataCompleted(object sender, ESRI.ArcGIS.Client.Tasks.GPParameterEventArgs e)
{
  // Get the GPDataFile from the e.Parameter.
  ESRI.ArcGIS.Client.Tasks.GPDataFile myGPDataFile = e.Parameter as ESRI.ArcGIS.Client.Tasks.GPDataFile;
  
  // Make sure we have a valid result.
  if (myGPDataFile != null)
  {
    // Get the Url String.
    string myUrl = myGPDataFile.Url;
    
    // Create a Uri from the Url String.
    Uri myUri = new Uri(myUrl);
    
    // Open a new internet browser window with the generated image from the PrintTask.
    System.Windows.Browser.HtmlPage.Window.Navigate(myUri, "_blank");
    
    // Display an informational message.
    ListBox_InfoMessage.Items.Add("The image file was returned in a web browser.");
  }
}
VB.NETCopy Code
' Create Global (aka. Member) variables for the PrintTask and Geoprocessor objects that will be 
' used in other parts of the application.
Private _PrintTask As ESRI.ArcGIS.Client.Printing.PrintTask
Private _Geoprocessor As ESRI.ArcGIS.Client.Tasks.Geoprocessor
            
Public Sub New()
            
  InitializeComponent()
  
  ' Provide a valid PrintTask.Url for a "asynchronous geoprocessing task"
  TextBox_Url.Text = "http://localhost:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export20Web20Map%20Task"
  
  ' Set the _PrintTask variable to a new instance of the PrintTask Class.
  _PrintTask = New ESRI.ArcGIS.Client.Printing.PrintTask()
  
  ' Prevent the internet browser from using a cache for the PrintTask operations.
  _PrintTask.DisableClientCaching = True
  
  ' Set the PrintTask.Url from what is entered in the TextBox.
  _PrintTask.Url = TextBox_Url.Text
  
  ' Wire up an Event Handler for the PrintTask.StatusUpdated Event.
  AddHandler _PrintTask.StatusUpdated, AddressOf printTask_StatusUpdated
  
  ' Set the _Geoprocessor variable to a new instance of the Geoprocessor Class.
  _Geoprocessor = New ESRI.ArcGIS.Client.Tasks.Geoprocessor
  
  ' Set the Geoprocessor.Url from what is entered in the TextBox.
  _Geoprocessor.Url = TextBox_Url.Text
  
  ' Wire up an Event Handler for the Geoprocessor.StatusUpdated Event.
  AddHandler _Geoprocessor.StatusUpdated, AddressOf geoprocessor_StatusUpdated
  
  ' Wire up an Event Handler for the Geoprocessor.GetResultDataCompleted Event.
  AddHandler _Geoprocessor.GetResultDataCompleted, AddressOf geoprocessor_GetResultDataCompleted
  
End Sub
            
Private Sub Button_SubmitJobAsync_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Define the settings for rendering the image/.pdf on the ArcGIS Server.
  
  ' Define the ExportOptions.
  Dim myExportOptions As New ESRI.ArcGIS.Client.Printing.ExportOptions
  myExportOptions.Dpi = 96 '96 DPI is typical Window OS setting.
  myExportOptions.OutputSize = New Size(MyMap.ActualWidth, MyMap.ActualHeight) ' Use the dimensions of the Map
  
  ' Define the PrintParameters. 
  Dim myPrintParameters As New ESRI.ArcGIS.Client.Printing.PrintParameters(MyMap)
  myPrintParameters.ExportOptions = myExportOptions ' Use the ExportOptions defined earlier.
  myPrintParameters.LayoutTemplate = "MAP_ONLY" ' Look to the REST service to see what layout templates are supported.
  myPrintParameters.Format = "PNG32" ' Look to the REST service to see what image formats are supported.
  
  ' Submit the 'PrintTask based asynchronous geoprocessing task' to ArcGIS Server. 
  _PrintTask.SubmitJobAsync(myPrintParameters)
  
  ' Enable the Button for the user to retieve the ArcGIS Server exported image/.pdf via the Geoprocessor.
  Button_GeoProcessor.IsEnabled = True
  
  ' Display an informational message.
  ListBox_InfoMessage.Items.Add("The PrintTask to generate the image was started.")
  
End Sub
  
Private Sub printTask_StatusUpdated(sender As Object, e As ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs)
  
  ' Use only for SubmitJobAsync operations (i.e. asynchronous geoprocessing tasks).
  
  ' This Event fires as a result of the PrintTask.SumbitJobAsync Method being used previously. It 
  ' can fire multiple times depending on the state of the geoprocessing task executing.
  
  ' Clear out the TextBlock any existing JobInfo messages.
  TextBlock_JobId.Text = ""
  
  ' Get the JobInfo information messages.
  Dim myJobInfo As ESRI.ArcGIS.Client.Tasks.JobInfo = e.JobInfo
  Dim myJobId As String = myJobInfo.JobId
  
  ' Display the JobInfo messages to the user.
  TextBlock_JobId.Text = myJobId
  
  ' Display an informational message.
  ListBox_InfoMessage.Items.Add("The PrintTask JobId was obtained.")
  
  ' As soon as we get our first update on the Job in this Event, call the PrintTask.CancelJobStatusUpdates 
  ' which will kill all future PrintTask.StatusUpdated Events (i.e. this Event) from firing. NOTE: the actual
  ' PrintTask job is still submitted to the ArcGIS Server geoprocessor and is running/completed.
  _PrintTask.CancelJobStatusUpdates(TextBlock_JobId.Text)
  
  ' Display some informational messages.
  ListBox_InfoMessage.Items.Add("All PrintTask messages have now been canceled.")
  ListBox_InfoMessage.Items.Add("And yet the ArcGIS Server PrintTask is still running.")
  ListBox_InfoMessage.Items.Add("Click the 'Get Job via Geoprocessor' to retrive the image.")
  
End Sub
  
Private Sub Button_GeoProcessor_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' We can no longer use the PrintTask Class to find out information about the "asynchronous geoprocessing task"
  ' that was submitted via the PrintTask.SubmitJobAsync() Method because the PrintTask.CancelJobStatusUpdates was 
  ' issued. We now need to use the Geoprocessor Class to find out information about the job by supplying the JobId 
  ' obtained in the last PrintTask.StatusUpdated Event.
  ' A common work flow for this type of situation might be a really long PrintTask job where the user needs to 
  ' close out of the application before the job completes. If the JobId was stored on disk or saved via some other
  ' mechanism, the image could still be retrieved via the Geoprocessor Class.
  _Geoprocessor.CheckJobStatusAsync(TextBlock_JobId.Text)
  
End Sub
            
Private Sub geoprocessor_StatusUpdated(sender As Object, e As ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs)
  
  ' This Event fires as a result of the Geoprocessor.CheckJobStatusAsync Method call.
  
  ' Get the JobInfo.
  Dim myJobInfo As ESRI.ArcGIS.Client.Tasks.JobInfo = e.JobInfo
  
  ' Ensure we have valid results.
  If myJobInfo IsNot Nothing Then
    
    ' Get the JobStatus from the JobInfo.
    Dim myJobStatus As ESRI.ArcGIS.Client.Tasks.esriJobStatus = myJobInfo.JobStatus
    
    ' The PrintTask operation that generates the image completed.
    If myJobStatus = ESRI.ArcGIS.Client.Tasks.esriJobStatus.esriJobSucceeded Then
      
      ' Display an informational message.
      ListBox_InfoMessage.Items.Add("The image file was found via the Geoprocessor.")
      
      ' Invoke the Geoprocessor.GetResultDataAsync Method so we can retrieve the image.
      ' The string parameter "Output_File" was obtained from the 'ArcGIS REST Service Directory' 
      ' for the Url of the PrintTask and Geoprocessor services. Look for the 'Parameter' that is 
      ' of 'Direction' esriGPParameterDirectionOutput.
      _Geoprocessor.GetResultDataAsync(TextBlock_JobId.Text, "Output_File")
      
    End If
    
  End If
  
End Sub
            
Private Sub geoprocessor_GetResultDataCompleted(sender As Object, e As ESRI.ArcGIS.Client.Tasks.GPParameterEventArgs)
  
  ' Get the GPDataFile from the e.Parameter.
  Dim myGPDataFile As ESRI.ArcGIS.Client.Tasks.GPDataFile = TryCast(e.Parameter, ESRI.ArcGIS.Client.Tasks.GPDataFile)
  
  ' Make sure we have a valid result.
  If myGPDataFile IsNot Nothing Then
    
    ' Get the Url String.
    Dim myUrl As String = myGPDataFile.Url
    
    ' Create a Uri from the Url String.
    Dim myUri As New Uri(myUrl)
    
    ' Open a new internet browser window with the generated image from the PrintTask.
    System.Windows.Browser.HtmlPage.Window.Navigate(myUri, "_blank")
    
    ' Display an informational message.
    ListBox_InfoMessage.Items.Add("The image file was returned in a web browser.")
    
  End If
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

© ESRI, Inc. All Rights Reserved.