سؤال

I am working on an application that connects to Database as soon as it opens. Sometimes, it takes about 10-15 seconds before the database file gets connected and until then, no controls are loaded, it just loads a blank window and the cursor shows working. I tried using this library to use an animated GIF but it is not loading it before trying DB connection. I am using SQL Server Express and connecting to an mdf file. I tried placing code to display the <image/> before the SqlConnection and SqlDataAdapter Objects but even that didn't help. Any suggestions would be appreciated. Thanks in advance.

هل كانت مفيدة؟

المحلول

Do all the loading processes on a different thread, Best way to do this is to use a BackgroundWorker

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

Initialize bw.WorkerSupportsCancellation = true; bw.WorkerReportsProgress = true; bw.DoWork += new DoWorkEventHandler(bw_DoWork);

Usage private void bw_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker;

    for (int i = 1; (i <= 10); i++)
    {
        if ((worker.CancellationPending == true))
        {
            e.Cancel = true;
            break;
        }
        else
        {
            // Perform a time consuming operation and report progress.
            System.Threading.Thread.Sleep(500);
            worker.ReportProgress((i * 10));
        }
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top