LazyInitializer Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides lazy initialization routines.
public ref class LazyInitializer abstract sealed
public static class LazyInitializer
type LazyInitializer = class
Public Class LazyInitializer
- Inheritance
-
LazyInitializer
The following example demonstrates how to use EnsureInitialized to lazily initialize a value using a Boolean value to track whether initialization has already happened and an object to use as the mutual exclusion lock.
Dim _data As ExpensiveData = Nothing
Dim _dataInitialized As Boolean = False
Dim _dataLock As Object = Nothing
' ...
Dim name = LazyInitializer.EnsureInitialized(_data, _dataInitialized, _dataLock)
ExpensiveData _data = null;
bool _dataInitialized = false;
object _dataLock = new object();
// ...
ExpensiveData dataToUse = LazyInitializer.EnsureInitialized(ref _data, ref _dataInitialized, ref _dataLock);
These routines avoid needing to allocate a dedicated, lazy-initialization instance, instead using references to ensure targets have been initialized as they are accessed.
Ensure |
Initializes a target reference or value type by using a specified function if it hasn't already been initialized. |
Ensure |
Initializes a target reference or value type with its parameterless constructor if it hasn't already been initialized. |
Ensure |
Initializes a target reference type by using a specified function if it hasn't already been initialized. |
Ensure |
Initializes a target reference type with a specified function if it has not already been initialized. |
Ensure |
Initializes a target reference type with the type's parameterless constructor if it hasn't already been initialized. |
제품 | 버전 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
The methods of LazyInitializer are thread-safe and may be called from multiple threads concurrently.
.NET 피드백
.NET은(는) 오픈 소스 프로젝트입니다. 다음 링크를 선택하여 피드백을 제공해 주세요.