InterlockedFlag Struct
Implements thread-safe management of a boolean value.
public struct InterlockedFlag : IEquatable<InterlockedFlag>, IEquatable<bool>- Implements
Constructors
| Name | Description |
|---|---|
| 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
valuebool- The initial value of the flag.
Properties
| Name | Description |
|---|---|
| Value | Gets or sets a value indicating whether the flag is set. This property is thread-safe. |
Value
Methods
| Name | Description |
|---|---|
| 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.
Equals overloads
Equals(InterlockedFlag)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(InterlockedFlag other)Parameters
otherInterlockedFlag- An object to compare with this object.
Returns
bool true if the current object is equal to the other parameter; otherwise, false.
Equals(bool)
Equals(object?)
GetHashCode()
ToString()
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.
Operators
| Name | Description |
|---|---|
| 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
aInterlockedFlag- The first flag to compare.
bInterlockedFlag- 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
aInterlockedFlag- The interlocked flag to compare.
bbool- 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
aInterlockedFlag- The first flag to compare.
bInterlockedFlag- 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
aInterlockedFlag- The interlocked flag to compare.
bbool- The value to compare.
Returns
bool true if the value of a is different from b; otherwise, false.