Method DisposeAsync
- Namespace
- DotNetBrowser.Browser
- Assembly
- DotNetBrowser.dll
DisposeAsync(BrowserDisposeOptions)
Asynchronously disposes the current browser instance according to the given options.
Task<bool> DisposeAsync(BrowserDisposeOptions browserDisposeOptions)
Parameters
browserDisposeOptions
BrowserDisposeOptionsbrowser dispose options.
Returns
- Task<bool>
The task that represents the result of the asynchronous dispose process.
True
indicates that the browser instance is successfully disposed without any dialogs,false
if the dispose process was canceled. This may happen if the BeforeUnloadHandler handler was invoked and the Stay() response was sent.
Remarks
If the currently loaded web page registers the onbeforeunload
JavaScript event
and the given options tell the browser to fire the beforeunload
event, then this method will not dispose the browser right away.
The BeforeUnloadHandler will be invoked in this case and if the handler tells the browser to stay on the web page, then the browser will not be disposed.
The following example demonstrates how to dispose the browser instance as if a user manually clicking the close button of the tab/window.
browser.DisposeAsync(new BrowserDisposeOptions(){BeforeUnloadEventHandled = true});
If the browser is already disposed, then this method does nothing.
Exceptions
- ObjectDisposedException
The IBrowser has already been disposed.
- ConnectionClosedException
The connection to the Chromium engine is closed.