private void btn_Start_Click(object sender, RoutedEventArgs e)
pb_loader.IsIndeterminate = true; //<- it has to start to make animation
IEmailService emailService = new EmailService();
IUserQueryService emailQueryService = new UserQueryService();
var idIniziale = int.Parse(txtIdIniziale.Text);
var idFinale = int.Parse(txtIdFinale.Text);
var n = idFinale - idIniziale;
string mail = "";
for(int i=0; i<=n; i++)
mail = txtMail.Text + idIniziale + "@mail.local";
var exist = emailQueryService.CheckUserExist(mail); //<- db operation method
if (exist == false)
var lastUniqueId = emailQueryService.GetLastUniqueId();//<- db operation method
lastUniqueId = lastUniqueId + 1;
var idUtente = emailService.SalvaUtente(mail, lastUniqueId); //<- db operation method
emailService.AssegnaReferente(idUtente, txtMail.Text);//<- db operation method
emailService.AssegnaRuoli(idUtente); //<- db operation method
idIniziale++;
pb_loader.IsIndeterminate = false; //<- it has to end animation of loading
}
private async void btn_Start_Click(object sender, RoutedEventArgs e)
// prevent click while operation in progress
btn_Start.IsEnabled = false;
pb_loader.IsIndeterminate = true;
// access UI elements before running the Task
var mail = txtMail.Text + idIniziale + "@mail.local";
await Task.Run(() =>
// perform background operation
// use local variables "mail" etc. here