IClosable IClosable IClosable IClosable Interface

Defines a method to release allocated resources.

.NET This interface appears as System.IDisposable.

C++/CX This interface appears as Platform::IDisposable.

Syntax

Declaration

public interface IClosablepublic interface IClosablePublic Interface IClosablepublic interface IClosable

Remarks

This interface is projected to a different interface for all possible languages, so it should be considered as an infrastructure piece that the overall Windows Runtime programming experience uses as an implementation detail. There are no typical app development scenarios that rely on implementing or using the IClosable interface directly, unless you're using WRL. For more info, see WRL Integration.

Notes to implementers

When programming with .NET, this interface is hidden and is replaced by the System.IDisposable interface.

If you are defining a runtime class in C++/CX and define a destructor, don't implement IClosable. There's already compiler-based behavior that implements a cleanup behavior for you, (as Platform::IDisposable) and your explicit implementation will clash with the built-in behavior. For more info, see the "Destructors" section of Ref classes and structs (C++/CX).

The purpose of this interface (as exposed by the languages) is so that Windows Runtime objects can wrap and dispose of exclusive system or device/hardware resources appropriately, such as file handles and network sockets. You do not implement this interface for Windows Runtime objects that wrap shared system resources, such as memory and shareable devices.

Notes to callers

The scenario for Platform::IDisposable/System.IDisposable is to support language-specific syntax that isolates references, such as the using() syntax in C#, or scoping behavior for reference counting in C++. Actually casting to the interfaces or invoking its methods from any app code in any language is rarely necessary.

Methods summary

Releases system resources that are exposed by a Windows Runtime object.

.NET This interface appears as System.IDisposable.

C++/CX This interface appears as Platform::IDisposable.

Methods

  • Close()
    Close()
    Close()
    Close()

    Releases system resources that are exposed by a Windows Runtime object.

    .NET This interface appears as System.IDisposable.

    C++/CX This interface appears as Platform::IDisposable.

    public void Close()public void Close()Public Function Close() As voidpublic void Close()

    Remarks

    Implementation / caller notes that follow are mainly relevant for WRL.

    Notes to implementers

    Implement this method to release the exclusive system resources that are in use, such as file handles, streams, and network sockets. The method should also release other resources that are in use, including object references and memory, to prepare them for reuse.

    This method must call the Close() method of any object it holds that implements IClosable.

    The Close() method should release system resources as quickly as possible, without blocking for asynchronous operations to complete. To ensure that all resources are completely released, the caller must wait for all outstanding asynchronous operations to complete before calling Close().

    After Close() returns, the object is still in memory but without the system resources it needs; therefore, most of its members are not usable. A member that depends on a released system resource can return RO_E_CLOSED to indicate that the object is closed and it cannot complete the requested operation.

    Notes to callers

    If you call Close() multiple times, there is no effect; the method returns S_OK.

    Close() methods aren't callable through Visual C++ component extensions (C++/CX) on Windows Runtime class instances where the class implemented IClosable. Instead, Visual C++ component extensions (C++/CX) code for runtime classes should call the destructor or set the last reference to null.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.FoundationContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.GuidAttribute

Details

Assembly

Windows.Foundation.dll