I am attempting to use a Microsoft.SqlServer.Management.Smo.Restore object to restore a SQL Server 2000 database. Just before I begin the restore operation, I change the text of a label so that the user knows what is going on. However, the changed text isn't visible on the GUI (i.e., the text remains the same as it was) until AFTER the fullRestore.Wait() line.
lblStatus.Text = "Restoring Database";
Restore fullRestore = new Restore();
// Configure fullRestore
fullRestore.SqlRestore(_server);
fullRestore.Wait();
The weird thing is, lblStatus eventually does display "Restoring Database", but not until after the restore is complete. Any ideas?
You're blocking on the GUI thread, which is preventing it from updating. You can call lblStatus.Refresh(), or move your Wait to a background thread (which is ultimately the right thing to do).