GCHandle.IsAllocated Property

Definition

获取一个值,该值指示是否分配了句柄。Gets a value indicating whether the handle is allocated.

public:
 property bool IsAllocated { bool get(); };
public bool IsAllocated { get; }
member this.IsAllocated : bool
Public ReadOnly Property IsAllocated As Boolean

Property Value

Boolean

如果分配了句柄,则为 true;否则为 falsetrue if the handle is allocated; otherwise, false.

Remarks

使用 Weak 句柄来确定 GCHandle 是否仍可用时使用此属性。Use this property when using Weak handles to determine if the GCHandle is still available. 当垃圾回收器收集对象时,Weak 句柄仍可在终结器中复活。When the garbage collector collects the object, the Weak handle can still be resurrected in the finalizer. 在这种情况下,不会分配句柄(当垃圾回收器尝试收集对象时,它会丢失),即使目标对象有效也是如此。In that case, the handle is not allocated (it is lost when the garbage collector attempts to collect the object), even though the target object is valid.

Applies to

See also