void OnWindowClosed(object sender, EventArgs e)
{
// If the browser window closes, return the focus to the main window
if (_window != null && _window.Owner != null)
{
_window.Owner.Focus();
}
// If the task wasn't completed, the user must have closed the window without logging in
if (_tcs != null && !_tcs.Task.IsCompleted)
{
// Set the task completion source exception to indicate a canceled operation
_tcs.SetException(new OperationCanceledException());
}
// Set the task completion source and window to null to indicate the authorization process is complete
_tcs = null;
_window = null;
}