private async void SearchBtnClick(object sender, EventArgs e) { string queryData = searchBar.Text; string queryFilter = filterBox.SelectedItem.ToString(); Task <PlayerInformationUserControl> querySearch = new Task <PlayerInformationUserControl>(() => Search(queryData, queryFilter)); querySearch.Start(); PlayerInformationUserControl playerInformation = await querySearch; if (playerInformation != null) { informationPanel.Controls.Clear(); informationPanel.Controls.Add(playerInformation); } }
// Makes a query about a player. Returns PlayerInformationUserControl if successful and null if not. private PlayerInformationUserControl Search(string _queryData, string _queryFilter) { if (string.IsNullOrWhiteSpace(_queryData)) { MessageBox.Show("Searchbar is empty or white spaces"); return(null); } else if (_queryFilter.Equals(filterBoxDefaultValue)) { MessageBox.Show("Pleace add search filter."); return(null); } else { if (_queryFilter.Equals("Name")) { Player player = searchEngine.SearchByName(_queryData); PlayerInformationUserControl playerInformation = new PlayerInformationUserControl() { PanelPlayer = player }; return(playerInformation); } else { Player player = searchEngine.SearchById(_queryData); PlayerInformationUserControl playerInformation = new PlayerInformationUserControl() { PanelPlayer = player }; return(playerInformation); } } }