Class AsyncDisposableOptions
Configuration options for IDisposable.
public class AsyncDisposableOptions : AsyncOptions, IAsyncOptions, IParameterObject
- Inheritance
-
AsyncDisposableOptions
- Implements
- Derived
- Inherited Members
Examples
The following example demonstrates how to configure AsyncDisposableOptions to control whether a disposable resource is left open after an async operation.
using System;
using System.IO;
using System.Threading.Tasks;
using Cuemon.IO;
namespace MyApp.Examples;
public class AsyncDisposableOptionsExample
{
public static async Task Main()
{
var options = new AsyncDisposableOptions
{
LeaveOpen = true
};
var stream = new MemoryStream();
// Use options.LeaveOpen to decide disposal behavior
if (!options.LeaveOpen)
{
stream.Dispose();
Console.WriteLine("LeaveOpen: {0}", options.LeaveOpen);
Console.WriteLine("Stream still open: {0}", stream.CanWrite);
// Output:
// LeaveOpen: True
// Stream still open: True
}}
}
Constructors
AsyncDisposableOptions()
Initializes a new instance of the AsyncDisposableOptions class.
public AsyncDisposableOptions()
Remarks
The following table shows the initial property values for an instance of AsyncDisposableOptions.
| Property | Initial Value |
|---|---|
| LeaveOpen | false |
Properties
LeaveOpen
Gets or sets a value indicating whether a disposable object should bypass the mechanism for releasing unmanaged resources. Default is false.
public bool LeaveOpen { get; set; }
Property Value
- bool
trueif a disposable object should bypass the mechanism for releasing unmanaged resources; otherwise,false.