Note that there are some explanatory texts on larger screens.

plurals
  1. POAsync method does not return control flow to form
    primarykey
    data
    text
    <p>I have a problem with my async method in WPF application. I want to implement asynch await pattern in my WPF application to retain form responsiveness when querying database with EntityFramework. I did everything as described in microsoft examples but it doesn't return control flow to the application as example applications do.</p> <p>Here is my button click code:</p> <pre><code>private async void LoginButton_Click(object sender, RoutedEventArgs e) { var loggedIn = await _gluUserRepository.LoginAsync(LoginTextBox.Text, PasswordTextBox.Text); Switcher.Switch(new Loader()); if (loggedIn) { UserName = LoginTextBox.Text; Switcher.Switch(new Blank()); } else { UserName = String.Empty; MessageBox.Show("Błędny login lub hasło. Spróbuj ponownie."); Switcher.Switch(new Login()); } } </code></pre> <p>Here is my LoginAsync method:</p> <pre><code>public async Task&lt;bool&gt; LoginAsync(string login, string password) { string hashedPassword = PasswordHasher.Hash(password); var user = await _dbContext.Users.FirstOrDefaultAsync(x =&gt; x.UserName == login); if (user != null &amp;&amp; user.Password == hashedPassword) return true; return false; } </code></pre> <p>I've seen the same usage of async/await in Microsoft example applications, however, their WPF apps return control to Window handle, i.e. I can move window around when in my app that is impossible. </p> <p><strong>What I want to achieve is using async/await pattern with WPF application to retain responsiveness of application. I want to display loading circle when querying database and return to method when querying has been completed.</strong></p> <p>Anyone has an idea what am I doing wrong? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload