private void _getFromUserBtn_Click(object sender, EventArgs e) { var search = _searchTB.Text; if (search == null || search.Trim().Length == 0) { return; } PrepareSearch(sender, e); AsyncLoader.DoAsync( () => _gitHoster.GetRepositoriesOfUser(search.Trim()), HandleSearchResult, ex => { if (ex.Exception.Message.Contains("404")) { MessageBox.Show(this, _strUserNotFound.Text, _strError.Text); } else { MessageBox.Show(this, _strCouldNotFetchReposOfUser.Text + Environment.NewLine + ex.Exception.Message, _strError.Text); } _searchBtn.Enabled = true; }); }
private void _getFromUserBtn_Click(object sender, EventArgs e) { var search = searchTB.Text; if (search == null || search.Trim().Length == 0) { return; } PrepareSearch(sender, e); ThreadHelper.JoinableTaskFactory.RunAsync( async() => { try { await TaskScheduler.Default; var repositories = _gitHoster.GetRepositoriesOfUser(search.Trim()); await this.SwitchToMainThreadAsync(); HandleSearchResult(repositories); } catch (Exception ex) when(!(ex is OperationCanceledException)) { await this.SwitchToMainThreadAsync(); if (ex.Message.Contains("404")) { MessageBox.Show(this, _strUserNotFound.Text, _strError.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(this, _strCouldNotFetchReposOfUser.Text + Environment.NewLine + ex.Message, _strError.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } searchBtn.Enabled = true; } }) .FileAndForget(); }