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:
bool ChangeState(
	[NotNullAttribute] string jobId,
	[NotNullAttribute] IState state,
	[CanBeNullAttribute] string expectedState


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

Return Value

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

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