InterlockedFlag Struct

Implements thread-safe management of a boolean value.

public struct InterlockedFlag : IEquatable<InterlockedFlag>, IEquatable<bool>
Implements

Constructors

NameDescription
InterlockedFlag(bool)Initializes a new instance of the InterlockedFlag struct.

InterlockedFlag(bool)

Initializes a new instance of the InterlockedFlag struct.

public InterlockedFlag(bool value)

Parameters

value bool
The initial value of the flag.

Properties

NameDescription
ValueGets or sets a value indicating whether the flag is set. This property is thread-safe.

Value

Gets or sets a value indicating whether the flag is set.

This property is thread-safe.

public bool Value { get; set; }

Property value

bool The value of the flag.

Methods

NameDescription
CheckAndSet(bool)Sets the value of an InterlockedFlag and returns the previous value. This method is thread-safe.
Equals(InterlockedFlag)Indicates whether the current object is equal to another object of the same type.
Equals(bool)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Indicates whether this instance and a specified object are equal.
GetHashCode()Returns the hash code for this instance.
ToString()Returns the fully qualified type name of this instance.
TryReset()Tries to reset the value of an InterlockedFlag to false. This method is thread-safe.
TrySet()Tries to set the value of an InterlockedFlag to true. This method is thread-safe.
TrySet(bool)Tries to set the value of an InterlockedFlag to the specified value. This method is thread-safe.

CheckAndSet(bool)

Sets the value of an InterlockedFlag and returns the previous value.

This method is thread-safe.

public bool CheckAndSet(bool value)

Parameters

value bool
The value to assign to the flag.

Returns

bool The previous value of the flag.

Equals overloads

Equals(InterlockedFlag)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(InterlockedFlag other)
Parameters
other InterlockedFlag
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(bool)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(bool other)
Parameters
other bool
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string The fully qualified type name.

TryReset()

Tries to reset the value of an InterlockedFlag to false.

This method is thread-safe.

public bool TryReset()

Returns

bool true if the flag has been reset; false if the value of the flag was already false.

TrySet overloads

TrySet()

Tries to set the value of an InterlockedFlag to true.

This method is thread-safe.

public bool TrySet()
Returns

bool true if the flag has been set; false if the flag was already set.

TrySet(bool)

Tries to set the value of an InterlockedFlag to the specified value.

This method is thread-safe.

public bool TrySet(bool value)
Parameters
value bool
The desired value to set.
Returns

bool true if the flag has been set to value; false if the value of the flag was already equal to value.

Operators

NameDescription
operator ==(InterlockedFlag, InterlockedFlag)Determines whether two specified interlocked flags have the same value.
operator ==(InterlockedFlag, bool)Determines whether a specified interlocked flag has the specified value.
operator !=(InterlockedFlag, InterlockedFlag)Determines whether two specified interlocked flags have different values.
operator !=(InterlockedFlag, bool)Determines whether a specified interlocked flag has a value different from a specified value.

op_Equality overloads

operator ==(InterlockedFlag, InterlockedFlag)

Determines whether two specified interlocked flags have the same value.

public static bool operator ==(InterlockedFlag a, InterlockedFlag b)
Parameters
a InterlockedFlag
The first flag to compare.
b InterlockedFlag
The second flag to compare.
Returns

bool true if the value of a is the same as the value of b; otherwise, false.

operator ==(InterlockedFlag, bool)

Determines whether a specified interlocked flag has the specified value.

public static bool operator ==(InterlockedFlag a, bool b)
Parameters
a InterlockedFlag
The interlocked flag to compare.
b bool
The value to compare.
Returns

bool true if the value of a is the same as b; otherwise, false.

op_Inequality overloads

operator !=(InterlockedFlag, InterlockedFlag)

Determines whether two specified interlocked flags have different values.

public static bool operator !=(InterlockedFlag a, InterlockedFlag b)
Parameters
a InterlockedFlag
The first flag to compare.
b InterlockedFlag
The second flag to compare.
Returns

bool true if the value of a is different from the value of b; otherwise, false.

operator !=(InterlockedFlag, bool)

Determines whether a specified interlocked flag has a value different from a specified value.

public static bool operator !=(InterlockedFlag a, bool b)
Parameters
a InterlockedFlag
The interlocked flag to compare.
b bool
The value to compare.
Returns

bool true if the value of a is different from b; otherwise, false.