I'm trying to create WPF client with IdentityServer authentication. I'm using their OidcClient
to get logged in. It's whole async while my app is sync and can't be refactored without huge effort. Calling
var result = await _oidcClient.LoginAsync();
doesn't wait for the result. Calling Wait()
or .Result
causes deadlock. Wrapping it to other Task.Run
is complaining that the method is not running on UI thread (it opens browser with login dialog).
Do you have any idea, how to solve this? Do I need to write custom sync OidcClient
?
As with other similar cases where you need to introduce asynchrony to a legacy app without much refactoring, I'd recommend using a simple "Please wait..." modal dialog. The dialog initiates an async operation and closes itself when the operation has finished.
Here is a basic but complete WPF example, mocking up
_oidcClient.LoginAsync()
withTask.Delay()
and executing it on the UI thread, refer toWpfTaskExt.Execute
for the details.Cancellation support is optional; if the actual
LoginAsync
can't be cancelled, the dialog is prevented from being closed prematurely.