ArcGIS Pro 2.7 API Reference Guide
OpenTaskAsync(String,Guid) Method
Example 

ArcGIS.Desktop.TaskAssistant Namespace > TaskAssistantModule Class > OpenTaskAsync Method : OpenTaskAsync(String,Guid) Method
Full path to an .esriTasks file.
The unique identifier of a task in the task file to be opened. If the task can be found, it is opened and ready to be executed. If the task cannot be found, the task file opens as if no task was specified.
Opens an ArcGIS Pro .esriTasks file. The file is added to the current project and loaded into the Tasks pane. Use the taskGuid parameter to specify a particular task in the task file to be opened. Use the GetTaskItemInfoAsync API call to obtain information about the tasks and their identifiers within the task file.
Syntax
public static Task<Guid> OpenTaskAsync( 
   string taskFile,
   Guid taskGuid
)
Public Overloads Shared Function OpenTaskAsync( _
   ByVal taskFile As String, _
   ByVal taskGuid As Guid _
) As Task(Of Guid)

Parameters

taskFile
Full path to an .esriTasks file.
taskGuid
The unique identifier of a task in the task file to be opened. If the task can be found, it is opened and ready to be executed. If the task cannot be found, the task file opens as if no task was specified.

Return Value

A Task returning the unique identifier of the task file opened. Use this unique identifier as parameters to other API calls such as CloseTaskAsync or ExportTaskAsync.
Exceptions
ExceptionDescription
Error opening the task file. For example the taskFile is invalid or the Tasks pane is in Designer mode and editing another task item.
This must be called on the UI thread.
Remarks
If the Tasks pane is not already visible, it will be opened. If the Tasks pane is visible, any current task item will be unloaded to allow the new item to be loaded.

If the Tasks pane is in Designer mode; then an OpenTaskException will be thrown. Task files can only be opened if the Tasks pane is not in Designer mode.

Example
// TODO - substitute your own .esriTasks file to be opened
string taskFile = @"c:\Tasks\Get Started.esriTasks";

try
{
  // retrieve the task item information
  TaskItemInfo taskItemInfo = await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);

  // find the first task
  TaskInfo taskInfo = taskItemInfo.GetTasks().FirstOrDefault();

  Guid guid = Guid.Empty;
  if (taskInfo != null)
  {
    // if a task exists, open it
    guid = await TaskAssistantModule.OpenTaskAsync(taskFile, taskInfo.Guid);
  }
  else
  {
    // else just open the task item
    guid = await TaskAssistantModule.OpenTaskAsync(taskFile);
  }

  // TODO - retain the guid returned for use with CloseTaskAsync 
}
catch (OpenTaskException e)
{
  // exception thrown if task file doesn't exist or has incorrect format
  ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}
catch (TaskFileVersionException e)
{
  // exception thrown if task file does not support returning task information
  ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

TaskAssistantModule Class
TaskAssistantModule Members
Overload List