void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Cancelled)
     {
         TextBoxThreading.AppendText("\n Task has been cancelled.");
     }
     else if (e.Error != null)
     {
         TextBoxThreading.AppendText("Error occured while performing task.");
     }
     ButtonPopulate.IsEnabled = true;
 }
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() => { CleanThreadingLog(); }));
            this.Dispatcher.Invoke((Action)(() => { TextBoxThreading.AppendText("Task: populate DataGrid \n\n"); }));

            List <Employee> employeeList = new List <Employee>();

            bgWorker.ReportProgress(10);

            this.Dispatcher.Invoke((Action)(() => { TextBoxThreading.AppendText("> Loading database into list... \n"); }));

            employeeList = dbManager.LoadDatabase();

            bgWorker.ReportProgress(50);

            if (bgWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            this.Dispatcher.Invoke((Action)(() => { TextBoxThreading.AppendText("> Database has been loaded \n"); }));
            this.Dispatcher.Invoke((Action)(() => { TextBoxThreading.AppendText("> Loading list into DataGrid... \n"); }));

            System.Threading.Thread.Sleep(300);

            if (bgWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            this.Dispatcher.Invoke((Action)(() => { MyDataGrid.DataContext = employeeList; }));
            this.Dispatcher.Invoke((Action)(() => { TextBoxThreading.AppendText("> DataGrid loaded! Task finished. \n"); }));

            bgWorker.ReportProgress(100);
        }