private async void GetUserDataBtn_Click(object sender, EventArgs e) { try { GetUserDataBtn.Enabled = false; CancelGetUserDataBtn.Enabled = true; GetUserDataCancellationTokenSource = new CancellationTokenSource(); string query = QueryStringTextbox.Text; query += "&limit=" + QueryPostLimitUpdown.Value; //Using 100 can cause a server error on API calls - "Please reduce the amount of data you're asking for, then retry your request" query += "&until=" + DateTimeToUnixTimestamp(UntilDatetimepicker.Value); AppendLineToOutput("Collecting query = " + query); //even though the method is async, running it in a task speeds up //this method's return to the UI await Task.Run(() => DataCollectionTasks.GetPageData(query , Convert.ToInt32(NumPostsToProcessUpdown.Value) , UserAccessToken , GetUserDataCancellationTokenSource.Token)); GetUserDataBtn.Enabled = true; CancelGetUserDataBtn.Enabled = false; ProcessNextLikeButton.Enabled = !string.IsNullOrEmpty(LikesNextTextbox.Text); ProcessNextCommentButton.Enabled = !string.IsNullOrEmpty(CommentsNextTextbox.Text); } catch (TaskCanceledException ex) { //this happens when a task is cancelled before it is started AppendLineToOutput("Unhandled exception: " + ex.Message + Environment.NewLine + ex.StackTrace); } }
private async void ProcessNextCommentButton_Click(object sender, EventArgs e) { ProcessNextCommentButton.Enabled = false; try { await Task.Run(() => DataCollectionTasks.ProcessCommentsFromQuery(CommentsNextTextbox.Text, UserAccessToken)); AppendLineToOutput("Process comments completed."); } catch (Exception ex) { AppendLineToOutput(ex.Message); } ProcessNextCommentButton.Enabled = true; }
private async void ProcessNextLikeButton_Click(object sender, EventArgs e) { ProcessNextLikeButton.Enabled = false; try { ProcessNextLikeCancellationTokenSource = new CancellationTokenSource(); await Task.Run(() => DataCollectionTasks.ProcessLikesFromQuery(LikesNextTextbox.Text, ProcessNextLikeCancellationTokenSource.Token, UserAccessToken)); AppendLineToOutput("Process likes completed."); } catch (Exception ex) { AppendLineToOutput(ex.Message); } ProcessNextLikeButton.Enabled = true; }