private async void GetGroupsBT_Click(object sender, EventArgs e) { Loading(GetGroupsBT, true); TLRequestMessagesGetDialogs req = new TLRequestMessagesGetDialogs(); req.setOffsetPeer(new TLInputPeerSelf()); req.setOffsetDate(0); req.setLimit(1000); //var res = NewApi.Api().doRpcCall(req); var res = await WTask.Task.Run(() => NewApi.Api().doRpcCall(req)); string notify = ""; if (res == null) { notify = "درخواست نتیجه ای نداشت!"; //NotifyBar.ForeColor = Color.Orange; } else { GroupsDGV.Rows.Clear(); ChannelsDGV.Rows.Clear(); TLDialogs Dailogs = (TLDialogs)res; /* * var ChanGP = Dailogs.getChats().toArray() * .Where(x => x.GetType() == typeof(TLChannel)) * .Cast<TLChannel>(); */ foreach (var dial in Dailogs.getChats()) { if (dial.GetType() == typeof(TLChat)) { TLChat chat = (TLChat)dial; GroupsDGV.Rows.Add(chat.getTitle(), "-", chat.getId(), 0); } else if (dial.GetType() == typeof(TLChannel)) { TLChannel chat = (TLChannel)dial; if ((chat.getId() + "").Substring(0, 3) != "100") { GroupsDGV.Rows.Add(chat.getTitle(), chat.getUsername(), chat.getId(), chat.getAccessHash()); } else { ChannelsDGV.Rows.Add(chat.getTitle(), chat.getUsername(), chat.getId(), chat.getAccessHash()); } } } } Loading(GetGroupsBT, false, notify); }