ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Workflow Namespace / WorkflowModule Class / ConnectAsync() Method
Example

In This Topic
    ConnectAsync() Method
    In This Topic
    Connects to the Workflow Manager repository in the project. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public static Task<WorkflowConnection> ConnectAsync()
    Public Shared Function ConnectAsync() As Task(Of WorkflowConnection)

    Return Value

    A Task returning the workflow connection information, ArcGIS.Desktop.Workflow.Models.WorkflowConnection.
    Exceptions
    ExceptionDescription
    No Workflow Manager connection found or there was an error connecting to the repository.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    A workflow connection instance should already exist in the project. If not, add a workflow connection prior to calling this method.
    Example
    Connect to Workflow Manager and create a new job
    var jobID = await QueuedTask.Run(async() =>
    {
        // Connect to the workflow connection.  The workflow connection provides connection status information and 
        // allows interaction with the Workflow Manager system through managers.
        WorkflowConnection connection = await WorkflowModule.ConnectAsync();
        
        // Access configuration and job information
        ConfigurationManager configMgr = connection.GetManager<ConfigurationManager>();
        var jobType = configMgr.GetVisibleJobTypes().FirstOrDefault();
        JobsManager jobsMgr = connection.GetManager<JobsManager>();
        return jobsMgr.CreateJob(jobType.ID);
    });
    How to get managers objects
    // WorkflowModule.GetManager returns a manager of the type specified
    // keyword is currently just an empty string
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var configManager = wfCon.GetManager<ConfigurationManager>();
    How to get groups
    // GetAllGroups returns a list of Workflow Manager groups
    var wfCon = await WorkflowModule.ConnectAsync();
    var configManager = wfCon.GetManager<ConfigurationManager>();
    var allGroups = configManager.GetAllGroups();
    How to get users
    // GetAllUsers returns a list of Workflow Manager users
    var wfCon = await WorkflowModule.ConnectAsync();
    var configManager = wfCon.GetManager<ConfigurationManager>();
    var allUsers = configManager.GetAllUsers();
    How to get job types
    // GetVisibleJobTypes returns a list of job types
    var wfCon = await WorkflowModule.ConnectAsync();
    var configManager = wfCon.GetManager<ConfigurationManager>();
    var jobTypes = configManager.GetVisibleJobTypes();
    How to create a job
    // CreateJob returns an ID of a new job
    // it is a passed a valid job type ID as an integer
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var jobID = jobManager.CreateNewJob(jobTypeID);
    How to get a job
    // GetJob returns an existing job
    // it is passed a valid job ID as an integer
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var job = jobManager.GetJob(jobID);
    How to get a job associated with a map
    // Get a job associated with the map
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var job = jobManager.GetJob(map);
    if (job != null)
    {
      // Job found, do something with the job
      var jobId = job.ID;
    }
    How to close a job
    // CloseJobs returns a list of closed job IDs
    // it is passed a list of job IDs to close
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var jobIDs = jobManager.CloseJobs(jobIdsToClose);
    How to access job info and change it
    // You can change many of the exposed properties of a job and then save them
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var job = jobManager.GetJob(jobID);
    job.Description = "This is a test";
    job.Save();
    How to Execute a step on a job
    // Gets the current step
    // checks to see if it can execute it
    // proceeds to do so if it can
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var job = jobManager.GetJob(jobID);
    string stepID = job.GetCurrentSteps().First();
    if (job.CanExecuteStep(stepID).Item1)
      job.ExecuteStep(stepID);
    How to execute a Query
    // ExecuteQuery returns a query result
    // Its passed either an ID or a name
    var wfCon = await WorkflowModule.ConnectAsync();
    var jobManager = wfCon.GetManager<JobsManager>();
    var queryResultReturn = jobManager.ExecuteQuery("All Jobs");
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also