There is a Task, it is necessary that at the time of its execution the button on the form is locked.

Task task = Task.Factory.StartNew(() => { // Тут идёт коннект к БД }); 

    1 answer 1

      public async void Start() { button.IsEnabled = false; await Task.Run(() => { //коннект к базе }); button.IsEnabled = true; } 

    For .NET 4.0, this option should work:

      public void Start() { button.IsEnabled = false; Task task = ConnectToDb(); task.ContinueWith(task1 => { button.IsEnabled = true; }, TaskScheduler.FromCurrentSynchronizationContext()); } private Task ConnectToDb() { return Task.Factory.StartNew(() => { //подключение к базе }); } 
    • And you can implement under 4.0 without async / await. - Knack
    • @ user212961, updated the answer. - Lightness
    • 3
      @Lightness: Not, task.Wait block the UI. Need task.ContinueWith on UI-scheduler. - VladD
    • one
      @VladD, Corrected. - Lightness