Click or drag to resize
IBackgroundJobClientChangeState Method
Attempts to change a state of a background job with a given identifier to a specified one.

Namespace: Hangfire
Assembly: Hangfire.Core (in Hangfire.Core.dll) Version: 1.5.0.0
Syntax
bool ChangeState(
	[NotNullAttribute] string jobId,
	[NotNullAttribute] IState state,
	[CanBeNullAttribute] string expectedState
)

Parameters

jobId
Type: SystemString
Identifier of background job, whose state should be changed.
state
Type: Hangfire.StatesIState
New state for a background job.
expectedState
Type: SystemString
Expected state assertion, or if unneeded.

Return Value

Type: Boolean
, if a given state was applied successfully otherwise .
Exceptions
ExceptionCondition
ArgumentNullExceptionjobId is null.
ArgumentNullExceptionstate is null.
BackgroundJobClientExceptionState change failed due to an exception.
Remarks

If expectedState value is not null, state change will be performed only if the current state name of a job equal to the given value.

The interface allows implementations to change a state of a background job to other than specified. The given state instance also may be modified. For example, ElectStateContext class contains public setter for the CandidateState property allowing to choose completely different state by state election filters. If a state was changed, value will be returned.

See Also