ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.TaskAssistant.Exceptions Namespace / OpenTaskException Class
Members Example

In This Topic
    OpenTaskException Class
    In This Topic
    Represents an error exception when opening an ArcGIS Pro .esriTasks file.
    Syntax
    public sealed class OpenTaskException : TaskException, System.Runtime.Serialization.ISerializable  
    Public NotInheritable Class OpenTaskException 
       Inherits TaskException
       Implements System.Runtime.Serialization.ISerializable 
    Remarks
    Example
    Open a Project Task Item
    {
      // get the first project task item
      var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();
      // if there isn't a project task item, return
      if (taskItem == null)
      {
        return;
      }
    
      try
      {
        // Open it
        //At 2.x -
        //System.Guid guid = await TaskAssistantModule.OpenTaskItemAsync(taskItem.TaskItemGuid);
        var guid = await TaskAssistantFactory.Instance.OpenTaskItemAsync(taskItem.TaskItemGuid);
    
        // TODO - retain the guid returned for use with CloseTaskItemAsync
      }
      catch (OpenTaskException e)
      {
        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
      }
    }
    Get Task Information - from a TaskProjectItem
    {
      var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();
      // if there isn't a project task item, return
      if (taskItem == null)
      {
        return;
      }
    
      string message = await QueuedTask.Run(async () =>
      {
        bool isOpen = taskItem.IsOpen;
        Guid taskGuid = taskItem.TaskItemGuid;
    
        string msg = "";
        try
        {
          TaskItemInfo taskItemInfo = await taskItem.GetTaskItemInfoAsync();
    
          msg = "Name : " + taskItemInfo.Name;
          msg += "\r\n" + "Description : " + taskItemInfo.Description;
          msg += "\r\n" + "Guid : " + taskItemInfo.Guid.ToString("B");
          msg += "\r\n" + "Task Count : " + taskItemInfo.GetTasks().Count();
    
          // iterate the tasks in the task item
          IEnumerable<TaskInfo> taskInfos = taskItemInfo.GetTasks();
          foreach (TaskInfo taskInfo in taskInfos)
          {
            string name = taskInfo.Name;
            Guid guid = taskInfo.Guid;
    
            // do something
          }
        }
        catch (OpenTaskException e)
        {
          // exception thrown if task file doesn't exist or has incorrect format
          msg = e.Message;
        }
        catch (TaskFileVersionException e)
        {
          // exception thrown if task file does not support returning task information
          msg = e.Message;
        }
        return msg;
      });
      ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(message, "Task Information");
    }
    Get Task Information - from an .esriTasks file
    {
      // TODO - substitute your own .esriTasks file
      string taskFile = @"c:\Tasks\Get Started.esriTasks";
    
      string message = await QueuedTask.Run(async () =>
      {
        string msg = "";
        try
        {
          // retrieve the task item information
          //At 2.x -
          //TaskItemInfo taskItemInfo = await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);
          TaskItemInfo taskItemInfo = await TaskAssistantFactory.Instance.GetTaskItemInfoAsync(taskFile);
    
          msg = "Name : " + taskItemInfo.Name;
          msg += "\r\n" + "Description : " + taskItemInfo.Description;
          msg += "\r\n" + "Guid : " + taskItemInfo.Guid.ToString("B");
          msg += "\r\n" + "Task Count : " + taskItemInfo.GetTasks().Count();
    
        }
        catch (OpenTaskException e)
        {
          // exception thrown if task file doesn't exist or has incorrect format
          msg = e.Message;
        }
        catch (TaskFileVersionException e)
        {
          // exception thrown if task file does not support returning task information
          msg = e.Message;
        }
        return msg;
      });
      ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(message, "Task Information");
    }
    Open a specific Task in a Task File - .esriTasks file
    {
      // TODO - substitute your own .esriTasks file to be opened
      string taskFile = @"c:\Tasks\Get Started.esriTasks";
    
      await QueuedTask.Run(async () =>
      {
        try
        {
          // retrieve the task item information
          //At 2.x -
          //TaskItemInfo taskItemInfo = await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);
          var taskItemInfo = await TaskAssistantFactory.Instance.GetTaskItemInfoAsync(taskFile);
    
          // find the first task
          TaskInfo taskInfo = taskItemInfo.GetTasks().FirstOrDefault();
    
          Guid guid = Guid.Empty;
          if (taskInfo != null)
          {
            // if a task exists, open it
            //At 2.x -
            //guid = await TaskAssistantModule.OpenTaskAsync(taskFile, taskInfo.Guid);
            guid = await TaskAssistantFactory.Instance.OpenTaskFileAsync(taskFile, taskInfo.Guid);
          }
          else
          {
            // else just open the task item
            //At 2.x -
            //guid = await TaskAssistantModule.OpenTaskAsync(taskFile);
            guid = await TaskAssistantFactory.Instance.OpenTaskFileAsync(taskFile);
          }
    
          // TODO - retain the guid returned for use with CloseTaskItemAsync
        }
        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);
        }
    
      });
    }
    Inheritance Hierarchy

    System.Object
       System.Exception
          ArcGIS.Desktop.TaskAssistant.Exceptions.TaskException
             ArcGIS.Desktop.TaskAssistant.Exceptions.OpenTaskException

    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also