private void getDataTaskComplete(object sender, TaskWorkerEventArgs e) { ProgressBarVisibility = Visibility.Hidden; ProgressBarIsEnabled = false; if (e.Parameters == null && e.Parameters is int == false && e.Results is Tuple <MultiModel, BitmapImage> == false && e.Cancelled) { return; } int index = (int)e.Parameters; if (index == SelectedIndex) { Tuple <MultiModel, BitmapImage> resultData = e.Results as Tuple <MultiModel, BitmapImage>; // The individual components need to be changed. If we replace the entire object, the selected index will go to zero. PersonTableResults[index].PersonDataTable = resultData.Item1.PersonDataTable; PersonTableResults[index].DetailsDataTable = resultData.Item1.DetailsDataTable; PersonTableResults[index].AddressDataTable = resultData.Item1.AddressDataTable; PersonDataResults = PersonTableResults[index]; Portrait = resultData.Item2; } }
private void connectTaskComplete(object sender, TaskWorkerEventArgs e) { ProgressBarVisibility = System.Windows.Visibility.Hidden; ProgressBarIsEnabled = false; bool success = false; if (e.Results != null && e.Results is bool) { success = (bool)e.Results; } if (success == false) { ConnectButtonContent = "Connect to Database"; return; } ConnectIsEnabled = false; string searchDefault = Config.Read("default_search").ToLower();; switch (searchDefault) { case "detailed": ChangeContent.Select(MainContent.Detailed); break; case "quick": default: ChangeContent.Select(MainContent.Quick); break; } // We are done with this control. }
// ViewModel Search Worker // --------------------------------------------------------------------------------------------------------------------------------------------- private void getDataTaskStart(object sender, TaskWorkerEventArgs e) { if (e.Parameters == null && e.Parameters is int == false) { return; } simulatedDelay(); if (getDataTask.CancellationRequested) { return; } int index = (int)e.Parameters; SQLFunctions sqlFunctions = new SQLFunctions(SQLConnection.DatabaseContext); MultiModel displayModel = null; displayModel = sqlFunctions.GetPersonDetails(PersonTableResults[index].PersonID); if (getDataTask.CancellationRequested) { return; } if (displayModel != null) { BitmapImage bitmapImage = ImageSourceReader.Read(displayModel.PhotoURL); e.Results = new Tuple <MultiModel, BitmapImage>(displayModel, bitmapImage);; } }
private void populateTaskComplete(object sender, TaskWorkerEventArgs e) { ProgressBarVisibility = Visibility.Hidden; ProgressBarIsEnabled = false; if (e.Cancelled) { return; } Page personPage = null; if (e.Results != null && e.Results is Page) { personPage = e.Results as Page; } PersonTableResults.Clear(); currentSearch = SearchTextbox; if (personPage.Results != null) { foreach (MultiModel person in personPage.Results) { PersonTableResults.Add(person); } PageCount = personPage.TotalPages; PageCurrent = personPage.ActivePage; } }
// ViewModel Search Worker // --------------------------------------------------------------------------------------------------------------------------------------------- private void populateTaskStart(object sender, TaskWorkerEventArgs e) { if (populateListViewTask.CancellationRequested) { return; } if (e.Parameters is Tuple <string, int> == false) { return; } Page personPage = null; Tuple <string, int> taskData = e.Parameters as Tuple <string, int>; simulatedDelay(); if (populateListViewTask.CancellationRequested) { return; } if (string.IsNullOrEmpty(taskData.Item1) || taskData.Item1.Length < 2 || taskData.Item2 < 1) { personPage = allDataPaginator(taskData.Item2); } else { personPage = searchPaginator(taskData.Item1, taskData.Item2); } e.Results = personPage; }
private void connectTaskStart(object sender, TaskWorkerEventArgs e) { ConnectMessage = "Connecting to local database..."; ConnectButtonContent = "Abort Connection"; ProgressBarIsEnabled = true; ProgressBarVisibility = System.Windows.Visibility.Visible; simulatedDelay(); if (taskWorker.CancellationRequested) { return; } // Connects to the Database. if (SQLConnection.Initialize(Statics.DatabaseFile)) { e.Results = true; } }
// Although this class method internally cleans up it is still good to expose this method just in case. public void Dispose() { try { if (task != null) { task.Dispose(); task = null; } if (source != null) { source.Dispose(); source = null; } } catch { // The above may fail is the task is somehow dead locked. Will look into this more. } taskWorkerEventArgs = new TaskWorkerEventArgs(); }