private void OnTextChanged(object sender, EventArgs me) { string keyword = ((TextBox)sender).Text; if (keyword.Length >= 2) { VisualizingTools.ShowWaitingAnimation(new Point(this.searchIcon.Left, this.searchBox.Bottom + 5), new Size(this.searchIcon.Width + this.searchBox.Width, this.searchBox.Height / 2), this); BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += (s, e) => { List <JObject> matchedJsonList = ServerRequest.GetFriendRequestsByKeyword(User.LoggedIn.Id, keyword); this.Invoke(new Action(() => { this.ShowMatchedList(matchedJsonList); })); }; backgroundWorker.RunWorkerCompleted += (s, e) => { backgroundWorker.Dispose(); VisualizingTools.HideWaitingAnimation(); }; backgroundWorker.RunWorkerAsync(); } }
private void ShowAllFriendRequests() { BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += (s, e) => { List <JObject> requestingUserJsonList = ServerRequest.GetFriendRequestsByKeyword(Consumer.LoggedIn.Id, ""); if (this.InvokeRequired) { this.Invoke(new Action(() => { ShowMatchedList(requestingUserJsonList); })); } else { ShowMatchedList(requestingUserJsonList); } }; backgroundWorker.RunWorkerAsync(); backgroundWorker.RunWorkerCompleted += (s, e) => { backgroundWorker.Dispose(); }; }