private async void GetContactsBT_Click(object sender, EventArgs e) { Loading(GetContactsBT, true); TLRequestContactsGetContacts req = new TLRequestContactsGetContacts(); req.setHash(""); //var res = NewApi.Api().doRpcCall(req); var res = await WTask.Task.Run(() => NewApi.Api().doRpcCall(req)); if (res == null) { NotifyBar.Text = "درخواست نتیجه ای نداشت!"; NotifyBar.ForeColor = Color.Orange; } else { ContactsDGV.Rows.Clear(); TLContacts Contacts = (TLContacts)res; foreach (TLUser contact in Contacts.getUsers()) { ContactsDGV.Rows.Add(contact.getFirstName() + " " + contact.getLastName(), contact.getUserName(), contact.getPhone(), contact.getId(), contact.getAccessHash()); } } GetContactsBT.Enabled = true; }
private async WTask.Task <TLUser> SearchContact(string UsernamePhone) { try { TLRequestContactsGetContacts req = new TLRequestContactsGetContacts(); req.setHash(""); //var res = NewApi.Api().doRpcCall(req); var res = await WTask.Task.Run(() => NewApi.Api().doRpcCall(req)); if (res == null) { NotifyBar.Text = "درخواست نتیجه ای نداشت!"; NotifyBar.ForeColor = Color.Orange; return(null); } else { TLContacts Contacts = (TLContacts)res; foreach (TLUser contact in Contacts.getUsers()) { if (contact.getUserName().ToLower() == UsernamePhone.Trim() || contact.getPhone() == UsernamePhone.Trim()) { return(contact); } } } } catch (Exception ex) { NotifyBar.Text = "خطا: " + ex.Message; NotifyBar.ForeColor = Color.Red; return(null); } return(null); }