private async void button_Click(object sender, RoutedEventArgs e)
{
await Task.Run(() => GO());
}
void GO()
{
string email = "null", password = "null";
Dispatcher.Invoke(() => { email = Email.Text; password = Password.Password; });
using (EFContext _context = new EFContext())
{
var res = _context.User.FirstOrDefault(x => x.Email == email && x.Password == password);
if (res != null)
{
Dispatcher.Invoke(() =>
{
MainWindow w = new MainWindow(res.Id);
w.Show();
this.Close();
});
}
else
{
Dispatcher.Invoke(() => IncorrectData.Visibility = Visibility.Visible);
}
}
}
Task task = null;
private async void button_Click(object sender, RoutedEventArgs e)
{
if(this.task != null)
{
return;
}
this.task = Task.Run(() => GO());
await this.task;
this.task = null;
}
void GO()
{
string email = "null", password = "null";
Dispatcher.Invoke(() => { email = Email.Text; password = Password.Password; });
using (EFContext _context = new EFContext())
{
var res = _context.User.FirstOrDefault(x => x.Email == email && x.Password == password);
if (res != null)
{
Dispatcher.Invoke(() =>
{
MainWindow w = new MainWindow(res.Id);
w.Show();
this.Close();
});
}
else
{
Dispatcher.Invoke(() => IncorrectData.Visibility = Visibility.Visible);
}
}
}