private async WTask.Task GetMessages(int uID, long uAccess, string type = "chat") { Loading(null, true); TLRequestMessagesGetHistory reqH = new TLRequestMessagesGetHistory(); reqH.setAddOffset(0); reqH.setLimit(100); reqH.setOffsetId(0); reqH.setOffsetDate(0); reqH.setMinId(0); reqH.setMaxId(999999); TLInputPeerUser upeer = new TLInputPeerUser(); TLInputPeerChat cpeer = new TLInputPeerChat(); TLInputPeerChannel chpeer = new TLInputPeerChannel(); switch (type.ToLower()) { case "user": upeer = new TLInputPeerUser(); upeer.setAccessHash(uAccess); upeer.setUserId(uID); reqH.setPeer(upeer); break; case "chat": cpeer = new TLInputPeerChat(); cpeer.setChatId(uID); reqH.setPeer(cpeer); break; case "channel": chpeer = new TLInputPeerChannel(); chpeer.setAccessHash(uAccess); chpeer.setChannelId(uID); reqH.setPeer(chpeer); break; default: break; } //var res = NewApi.Api().doRpcCall(reqH); var res = await WTask.Task.Run(() => NewApi.Api().doRpcCall(reqH)); string notify = ""; if (res == null) { notify = "درخواست نتیجه ای نداشت!"; //NotifyBar.ForeColor = Color.Orange; } else { MessagesDGV.Rows.Clear(); if (res.GetType() == typeof(TLMessages)) { try { TLMessages Messages = (TLMessages)res; foreach (var msg in Messages.getMessages()) { try { TLMessage message = (TLMessage)msg; MessagesDGV.Rows.Add(message.getDate(), message.getId(), message.getMessage(), uID, uAccess); } catch { } } } catch { } } else if (res.GetType() == typeof(TLMessagesSlice)) { try { TLMessagesSlice Messages = (TLMessagesSlice)res; foreach (var msg in Messages.getMessages()) { try { TLMessage message = (TLMessage)msg; MessagesDGV.Rows.Add(message.getDate(), message.getId(), message.getMessage(), uID, uAccess); } catch { } } } catch { } } else if (res.GetType() == typeof(TLChannelMessages)) { TLChannelMessages Messages = (TLChannelMessages)res; foreach (var msg in Messages.getMessages()) { try { TLMessage message = (TLMessage)msg; MessagesDGV.Rows.Add(message.getDate(), message.getId(), message.getMessage(), uID, uAccess); } catch { } } } } Loading(null, false, notify); }