ArcGIS Runtime SDK for WPF - Library Reference
SubmitJobAsync Method
See Also  Example
ESRI.ArcGIS.Client.Printing Namespace > PrintTask Class : SubmitJobAsync Method

printParameters
The print parameters.
userToken
The user token.
Submits a print job request to the server to execute an asynchronous geoprocessing task. Raises the StatusUpdated and JobCompleted.

Syntax

Visual Basic (Declaration) 
Public Sub SubmitJobAsync( _
   ByVal printParameters As PrintParameters, _
   Optional ByVal userToken As Object _
) 
C# 
public void SubmitJobAsync( 
   PrintParameters printParameters,
   object userToken
)

Remarks

Synchronous -vs- Asynchronous Geoprocessing Tasks

When it comes to using the PrintTask in web development using the ArcGIS Runtime SDK for WPF to generate an image on ArcGIS Server, as a developer you have two options: synchronous geoprocessing tasks and asynchronous geoprocessing tasks. In a traditional sense the terms "synchronous" means that your computer will wait while a process executes on the server and "asynchronous" means that your computer does not have to wait for the process to finish execution and you can move on to other operations. However in web development using the ArcGIS Runtime SDK for WPF, all web requests are asynchronous in nature, meaning that once a web request has initiated you are free to perform other operations/functionality in your application as it remains highly responsive. When it comes to the PrintTask there are some important differences between the synchronous geoprocessing tasks and asynchronous geoprocessing tasks that are outlined as follows:

  • A synchronous geoprocessing task means that once ArcGIS Server starts the task to generate the image, ArcGIS Server is dedicated to that operation until it completes. It should be noted that from the web based WPF application’s perspective, that once the synchronous geoprocessing task has been initiated you are still free to perform other operations as the application remains highly responsive. See the code example in the PrintTask.ExecuteAsync(PrintParameters,Object) Method for how a synchronous geoprocessing task works.
  • An asynchronous geoprocessing task means that ArcGIS Server will control when it can handle generating an image based upon its computing load and will multi-task multiple operations simultaneously until the operation is complete. Again it should be noted that from the web based WPF application’s perspective, that once the asynchronous geoprocessing task has been initiated you are still free to perform other operations as the application remains highly responsive. See the code example in this document for how an asynchronous geoprocessing task works.

When constructing a PrintTask the following Types are used by both the synchronous geoprocessing tasks or asynchronous geoprocessing tasks:

The following table illustrates which PrintTask Types are dedicated exclusively to a synchronous geoprocessing task or an asynchronous geoprocessing task:

Synchronous geoprocessing task Asynchronous geoprocessing task
CancelAsync Method CancelJobAsync Method
ExecuteAsync Method CancelJobStatusUpdates Method
GetServiceInfoAsync Method SubmitJobAsync Method
IsBusy Property UpdateDelay Property
ExecuteCompleted Event StatusUpdated Event
GetServiceInfoCompletedEvent JobCompleted Event

As a developer of a web based WPF application, when choosing whether to perform a PrintTask based upon the methodology of synchronous geoprocessing task or an asynchronous geoprocessing task, the following information may be helpful in the decision making process:

  • By default, a synchronous geoprocessing task is created when ArcGIS Server is installed and initially configured. This means that no other work is required on ArcGIS Server to enable using the PrintTask (other than starting the PrintingTools, Geoprocessing Service) by an WPF application developer. Typically in ArcGIS Server, this synchronous geoprocessing task is located under in the ArcGIS REST Services Directory in the Utilities folder as an Utilties/ExportWebMap (GPServer) Service. The Task is usually called Export Web Map Task and has an Execution Type of esriExecutionTypeSynchronous. For example, assume for the sample ESRI ArcGIS Server (http://servicesbeta2.esri.com/arcgis/rest/) the PrintTask.Url for the synchronous geoprocessing task would be as follows (see the following screen shot):

    Looking at the ArcGIS REST Services Directory of the default Export Web Map Task in Synchronous mode.

  • For small PrintTask operations using a synchronous geoprocessing task will probably yield faster results in generating a return image/pdf.

  • A web based WPF application can only issue one PrintTask via a synchronous geoprocessing task at a time. This means that it is not possible to have multiple PrintTask operations (i.e. generating multiple image/.pdf files at a time) using a synchronous geoprocessing task. Use the PrintTask.IsBusy Property to determine if an existing synchronous geoprocessing task is running before issuing the PrintTask.ExecuteAsync Method to avoid the Visual Studio runtime error: NotSupportedException was unhandled by user code ("Task does not support concurrent I/O operations. Cancel the pending request or wait for it to complete").

  • If multiple simultaneous PrintTask operations are necessary from a single web based WPF application (i.e. an application that produces numerous images/.pdf for cartographic production), then use the asynchronous geoprocessing task options for better performance.

  • If the PrintTask operations will be used for very large image/.pdf generation or numerous ArcGIS WPF applications will be utilizing a single ArcGIS Server and thereby causing internet browser time-out error messages, then an asynchronous geoprocessing task may be the better choice. It may be possible to increase the amount of time an internet browser waits before a time-out error message occurs when using a synchronous geoprocessing task but this will require testing to determine which option is best for your organization.

  • Using an asynchronous geoprocessing task requires configuring an ArcGIS Server Geoprocessing Task. This is not done automatically as part of the ArcGIS Server installation/configuration. One option is to use ArcMap to run the ArcToolbox: Server Tools | Printing | Export Web Map tool and when the Results are completed right click on the ExportWebMap session and Share As a Geoprocessing Service that can be used by ArcGIS Server. Another option is to use the default ArcGIS Server: Printing Tools, Geoprocessing Service (located in the Utilities folder) that is created when ArcGIS Server is initially installed/configured and change its Execution Mode from Synchronous to Asynchronous (see the following screen shot for an example test ArcGIS Server running on the local developement computer) and re-starting the service:

    Using ArcGIS Server Manager to change the Execution Mode of an Export Web Map Task.

    This will result in an ArcGIS REST Services Directory page that looks similar to the following screen shot:

    Looking at the ArcGIS REST Services Directory of an Export Web Map Task in Asynchronous mode.

  • Using the PrintTask via asynchronous geoprocessing task Types provide much better options to track the status of image/.pdf creation. The PrintTask.StatusUpdated Event uses the ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs Class to give instant status information of the operation.

Parameters

printParameters
The print parameters.
userToken
The user token.

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' button to generate a .JPG image returned in an internet browser. JobInfo messages will display to provide status information on the PrintTask operation. Experiment by changing the 'UpdateDelay' setting as well as clicking the 'CancelJobAsync' button to see their effect on the PrintTask operation.

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.

Demonstrating how to use the PrintTask.SubmitJobAsync Method for an asynchronous geoprocessing task.

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,261,0,0" 
            Name="MyMap" VerticalAlignment="Top" WrapAround="True" Height="300" Width="600"
             Extent="-10929488.234,4525208.388,-10906776.553,4535252.104">
    <esri:Map.Layers>
      <esri:LayerCollection>
                  
        <!-- Add some layers to the Map Control. -->
        <esri:ArcGISTiledMapServiceLayer 
          Url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
        <esri:ArcGISDynamicMapServiceLayer 
          Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/MapServer" />
        <esri:FeatureLayer Mode="OnDemand" DisableClientCaching="True" 
          Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSWells/MapServer/0" />
          
      </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" />
  
  <!-- UpdateDelay -->
  <sdk:Label Height="19" HorizontalAlignment="Left" Margin="14,156,0,0" Name="Label1" VerticalAlignment="Top" 
             Width="80"  Content="UpdateDelay:" />
  <TextBox Height="23" HorizontalAlignment="Left" Margin="14,174,0,0" Name="TextBox_UpdateDelay" 
           VerticalAlignment="Top" Width="80" Text="1000"/>
  
  <!-- Buttons to perform the work. -->
  <Button Content="SubmitJobAsync" Height="23" Width="201" HorizontalAlignment="Left" Margin="110,144,0,0" 
          Name="Button_SubmitJobAsync" VerticalAlignment="Top" Click="Button_SubmitJobAsync_Click" IsEnabled="True"/>
  <Button Content="CancelJobAsync" Height="23" Width="201" HorizontalAlignment="Left" Margin="110,173,0,0" 
          Name="Button_CancelJobAsync" VerticalAlignment="Top" Click="Button_CancelJobAsync_Click" IsEnabled="False"/>
  
  <!-- JobInfo -->
  <sdk:Label Height="16" HorizontalAlignment="Left" Margin="341,147,0,0" Name="Label_JobId" VerticalAlignment="Top" 
             Width="35" Content="JobId:"/>
  <TextBlock Height="16" HorizontalAlignment="Left" Margin="382,147,0,0" Name="TextBlock_JobId" 
             VerticalAlignment="Top" Width="231" />
  <sdk:Label Height="15" Margin="317,169,0,0" Name="Label_JobStatus" VerticalAlignment="Top" Content="JobStatus:" 
             HorizontalAlignment="Left" Width="65" />
  <TextBlock Height="15" Margin="382,169,12,0" Name="TextBlock_JobStatus" VerticalAlignment="Top" />
  <sdk:Label Height="23" HorizontalAlignment="Left" Margin="317,192,0,0" Name="Label_Messages" VerticalAlignment="Top" 
             Width="65" Content="Messages:"/>
  <ListBox Height="64" HorizontalAlignment="Left" Margin="382,192,0,0" Name="ListBox_Messages" VerticalAlignment="Top" 
           Width="231" />
    
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="91" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="790" 
     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' button to generate a
      .JPG image returned in an internet browser. JobInfo messages will display to provide status information 
      on the PrintTask operation. Experiment by changing the 'UpdateDelay' setting as well as clicking the
      'CancelJobAsync' button to see their effect on the PrintTask operation." />
  
</Grid>
C#Copy Code
// Create a Global (aka. Member) variable for the PrintTask object that will be used in other 
// parts of the application.
private ESRI.ArcGIS.Client.Printing.PrintTask _PrintTask;
            
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;
  
  // Wire up an Event Handler for the PrintTask.JobCompleted Event.
  _PrintTask.JobCompleted += printTask_JobCompleted;
}
            
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 = "JPG"; // Look to the REST service to see what image formats are supported.
  
  // The UpdateDelay specifys how long (in milliseconds) to wait between asynchronous executions. 
  _PrintTask.UpdateDelay = Convert.ToInt32(TextBox_UpdateDelay.Text);
  
  // Submit the asynchronous geoprocessing task to ArcGIS Server. 
  _PrintTask.SubmitJobAsync(myPrintParameters);
  
  // Enable button for the user to cancel the PrintTask request.
  Button_CancelJobAsync.IsEnabled = true;
}
            
private void printTask_JobCompleted(object sender, ESRI.ArcGIS.Client.Printing.PrintJobEventArgs e)
{
  // Use only for SubmitJobAsync operations (i.e. asynchronous geoprocessing tasks).
  
  // Test if we have valid results coming back from ArcGIS Server.
  if (e.PrintResult != null)
  {
    if (e.PrintResult.Url != null)
    {
      // Open a new internet browser window with the generated image from the PrintTask. 
      System.Windows.Browser.HtmlPage.Window.Navigate(e.PrintResult.Url, "_blank");
      
      // Clear out the JobInfo messages since we have completed the asynchronous geoprocessing task. 
      TextBlock_JobId.Text = "";
      TextBlock_JobStatus.Text = "";
      ListBox_Messages.Items.Clear();
    }
  }
}
            
private void Button_CancelJobAsync_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Use only for SubmitJobAsync operations (i.e. asynchronous geoprocessing tasks).
  
  // This will kill the asynchronous geoprocessing task. Notifications via the PrintTask.StatusUpdated Event
  // will still occur.
_PrintTask.CancelJobAsync(TextBlock_JobId.Text);
}
            
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 any existing JobInfo messages.
  TextBlock_JobId.Text = "";
  TextBlock_JobStatus.Text = "";
  ListBox_Messages.Items.Clear();
  
  // Get the JobInfo information messages.
  ESRI.ArcGIS.Client.Tasks.JobInfo myJobInfo = e.JobInfo;
  string myJobId = myJobInfo.JobId;
  ESRI.ArcGIS.Client.Tasks.esriJobStatus myJobStatus = myJobInfo.JobStatus;
  List<ESRI.ArcGIS.Client.Tasks.GPMessage> myMessages = myJobInfo.Messages;
  
  // Display the JobInfo messages to the user.
  TextBlock_JobId.Text = myJobId;
  TextBlock_JobStatus.Text = myJobStatus.ToString();
  foreach (ESRI.ArcGIS.Client.Tasks.GPMessage myMessage in myMessages)
  {
    ListBox_Messages.Items.Add(myMessage.Description);
  }
}
VB.NETCopy Code
' Create a Global (aka. Member) variable for the PrintTask object that will be used in other 
' parts of the application.
Private _PrintTask As ESRI.ArcGIS.Client.Printing.PrintTask
            
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
  
  ' Wire up an Event Handler for the PrintTask.JobCompleted Event.
  AddHandler _PrintTask.JobCompleted, AddressOf printTask_JobCompleted
  
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 = "JPG" ' Look to the REST service to see what image formats are supported.
  
  ' The UpdateDelay specifys how long (in milliseconds) to wait between asynchronous executions. 
  _PrintTask.UpdateDelay = CInt(TextBox_UpdateDelay.Text)
  
  ' Submit the asynchronous geoprocessing task to ArcGIS Server. 
  _PrintTask.SubmitJobAsync(myPrintParameters)
  
  ' Enable button for the user to cancel the PrintTask request.
  Button_CancelJobAsync.IsEnabled = True
  
End Sub
            
Private Sub printTask_JobCompleted(sender As Object, e As ESRI.ArcGIS.Client.Printing.PrintJobEventArgs)
  
  ' Use only for SubmitJobAsync operations (i.e. asynchronous geoprocessing tasks).
  
  ' Test if we have valid results coming back from ArcGIS Server.
  If e.PrintResult IsNot Nothing Then
    If e.PrintResult.Url IsNot Nothing Then
      
      ' Open a new internet browser window with the generated image from the PrintTask. 
      System.Windows.Browser.HtmlPage.Window.Navigate(e.PrintResult.Url, "_blank")
      
      ' Clear out the JobInfo messages since we have completed the asynchronous geoprocessing task. 
      TextBlock_JobId.Text = ""
      TextBlock_JobStatus.Text = ""
      ListBox_Messages.Items.Clear()
      
    End If
  End If
  
End Sub
            
Private Sub Button_CancelJobAsync_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Use only for SubmitJobAsync operations (i.e. asynchronous geoprocessing tasks).
  
  ' This will kill the asynchronous geoprocessing task. Notifications via the PrintTask.StatusUpdated Event
  ' will still occur.
  _PrintTask.CancelJobAsync(TextBlock_JobId.Text)
  
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 any existing JobInfo messages.
  TextBlock_JobId.Text = ""
  TextBlock_JobStatus.Text = ""
  ListBox_Messages.Items.Clear()
  
  ' Get the JobInfo information messages.
  Dim myJobInfo As ESRI.ArcGIS.Client.Tasks.JobInfo = e.JobInfo
  Dim myJobId As String = myJobInfo.JobId
  Dim myJobStatus As ESRI.ArcGIS.Client.Tasks.esriJobStatus = myJobInfo.JobStatus
  Dim myMessages As List(Of ESRI.ArcGIS.Client.Tasks.GPMessage) = myJobInfo.Messages
  
  ' Display the JobInfo messages to the user.
  TextBlock_JobId.Text = myJobId
  TextBlock_JobStatus.Text = myJobStatus.ToString
  For Each myMessage As ESRI.ArcGIS.Client.Tasks.GPMessage In myMessages
    ListBox_Messages.Items.Add(myMessage.Description)
  Next
  
End Sub

Requirements

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

See Also

© ESRI, Inc. All Rights Reserved.