# Class ProcessStatusWait OptimaJet.Workflow.Core.Runtime.ProcessStatusWait Acquires exclusive execution access to a process by changing its persisted status to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/), waiting and retrying when the process is already being executed. Namespace: [OptimaJet.Workflow.Core.Runtime](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime/) ```csharp public sealed class ProcessStatusWait : IDisposable ``` ## Type Hierarchy - ProcessStatusWait Current type - Implemented interfaces - [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable) ## Constructors `public ProcessStatusWait(WorkflowRuntime runtime, Guid processToWaitId, Guid calleeProcessId)` Initializes a coordinator that can acquire execution access to the target process on behalf of another process. ### Parameters | Name | Type | Description | | --- | --- | --- | | `runtime` | `WorkflowRuntime` | The workflow runtime whose persistence provider and status-change notifications are used. | | `processToWaitId` | `Guid` | The identifier of the target process whose status must be changed to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/). | | `calleeProcessId` | `Guid` | The identifier of the process on whose behalf execution access to the target process is requested. | ### Remarks Construction does not access persistence or subscribe to runtime events. Acquisition starts when a [ProcessStatusWait.LockOrStartWaiting(TimeSpan, CancellationToken)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime/ProcessStatusWait/) overload is called. ## Methods `public Task LockOrStartWaiting()` Attempts to acquire execution access to the target process, using 30 seconds as the timeout for each wait cycle. ### Returns | Type | Description | | --- | --- | | `Task` | [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the target process status was changed to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/); [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the process does not have a defined status or access could not be acquired within the retry budget. | ### Remarks The 30-second timeout applies separately to each wait cycle, not to the entire operation. `public Task LockOrStartWaiting(CancellationToken cancellationToken)` Attempts to acquire execution access to the target process, waiting without a timeout until a status change is detected or the provided token cancels the current wait. ### Parameters | Name | Type | Description | | --- | --- | --- | | `cancellationToken` | `CancellationToken` | A token that stops an in-progress wait between acquisition attempts. It is not passed to persistence operations. | ### Returns | Type | Description | | --- | --- | | `Task` | [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the target process status was changed to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/); [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the process does not have a defined status or access could not be acquired within the retry budget. | ### Remarks Cancellation ends the current wait without throwing [OperationCanceledException](https://learn.microsoft.com/dotnet/api/system.operationcanceledexception). The method still performs its remaining immediate acquisition attempts and can return [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if one of them succeeds. `public Task LockOrStartWaiting(TimeSpan timeout)` Attempts to acquire execution access to the target process, using the specified timeout for each wait cycle. ### Parameters | Name | Type | Description | | --- | --- | --- | | `timeout` | `TimeSpan` | The maximum duration of each wait for a status-change notification or persistence polling result. Specify [Timeout.InfiniteTimeSpan](https://learn.microsoft.com/dotnet/api/system.threading.timeout.infinitetimespan) to wait without a timeout. | ### Returns | Type | Description | | --- | --- | | `Task` | [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the target process status was changed to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/); [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the process does not have a defined status or access could not be acquired within the retry budget. | ### Remarks The timeout applies separately to each wait cycle, not to the entire operation. `public Task LockOrStartWaiting(TimeSpan timeout, CancellationToken cancellationToken)` Attempts to acquire execution access to the target process by changing its persisted status to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/), waiting and retrying while another operation is executing the process. ### Parameters | Name | Type | Description | | --- | --- | --- | | `timeout` | `TimeSpan` | The maximum duration of each wait for a status-change notification or persistence polling result. This is not an overall timeout. Specify [Timeout.InfiniteTimeSpan](https://learn.microsoft.com/dotnet/api/system.threading.timeout.infinitetimespan) to wait without a timeout. | | `cancellationToken` | `CancellationToken` | A token that stops an in-progress wait between acquisition attempts. It is not passed to persistence operations. | ### Returns | Type | Description | | --- | --- | | `Task` | [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the target process status was changed to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/), and the caller may proceed with the protected operation; [false](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the process does not have a defined status or access could not be acquired within the retry budget. | ### Remarks The first acquisition attempt is immediate. After the first conflict, the method subscribes to runtime status-change notifications and makes another immediate attempt to avoid missing a status change that occurred while the handler was being attached. A wait is released when the target enters [ProcessStatus.Idled](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/), [ProcessStatus.Finalized](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/), [ProcessStatus.Terminated](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/), or [ProcessStatus.Error](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/). The status is then changed to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/) atomically by the persistence provider; if another contender changes it first, waiting continues. In multi-server mode, the method waits for either the local runtime event or a persistence polling result. The polling interval is taken from [MultiServerSettings.ProcessStatusPollInterval](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Settings/MultiServerSettings/). The implementation performs up to four wait cycles after the initial conflict and makes a final immediate acquisition attempt. Consequently, the total duration can exceed `timeout`. Cancellation ends the current wait without throwing [OperationCanceledException](https://learn.microsoft.com/dotnet/api/system.operationcanceledexception). The method still performs its remaining immediate acquisition attempts and can return [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if one of them succeeds. `public void Dispose()` Stops this instance from receiving runtime status-change notifications and releases its waiting resources. ### Remarks This method does not change the target process status and therefore does not release execution access acquired by [ProcessStatusWait.LockOrStartWaiting(TimeSpan, CancellationToken)](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime/ProcessStatusWait/). The caller remains responsible for the target process's subsequent status transition or deletion. ## Remarks An acquisition attempt succeeds when the persistence provider changes the target process status to [ProcessStatus.Running](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Persistence/ProcessStatus/). If the status cannot be changed because another operation is using the process, this class waits until the process enters a non-running status and then tries again. In a single-server configuration, a retry is triggered by the runtime status-change event. In a multi-server configuration, the persisted status is also polled because the event can be raised on another server. The polling interval is taken from [MultiServerSettings.ProcessStatusPollInterval](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime.Settings/MultiServerSettings/). This class does not execute the target process and does not restore its status after a successful acquisition. The caller is responsible for completing the protected operation and performing the required subsequent status transition or process deletion. [Previous ProcessStatusChangedEventArgs](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime/ProcessStatusChangedEventArgs/) [Next ProcessTimer](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Runtime/ProcessTimer/)