IClosable.Close Method
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.
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();
void Close();
public void Close();
function close()
Public Sub Close ()
Implementation/caller notes that follow are mainly relevant for WRL.
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.
If you call Close multiple times, there is no effect; the method returns S_OK.
Close methods aren't callable through C++/CX on Windows Runtime class instances where the class implemented IClosable, but are automatically called at the end of the current scope. C++/CX code for runtime classes should call the destructor or set the last reference to null.
In C#, this method is exposed as Dispose. You can either call Dispose directly or use a using statement.
Product | Versions |
---|---|
WinRT | Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100 |