sochix / TLSharp

Telegram client library implemented in C#
1.01k stars 380 forks source link

Cannot send message while receiving through loops #812

Closed derodevil closed 5 years ago

derodevil commented 5 years ago

I find various errors during sending a text message using

SendMessageAsync

while listening to new incoming message. I am using this code to listen to new messages

while (true)
{
    var state = await SendRequestAsync<TLState>(new TLRequestGetState());
    //Unable to cast object of type 'TeleSharp.TL.Messages.TLAffectedMessages' to type 'TeleSharp.TL.Updates.TLState'. => this happens when sending new message
}

This is the code to send the message

TLInputPeerUser peer = new TLInputPeerUser() { UserId = id, AccessHash = hash };
await SendMessageAsync(peer, message);
//Somtimes errors occure, Invalid checsum skip! and sometimes Unable to cast object of type 'TeleSharp.TL.Messages.TLAbsMessage' to type 'TeleSharp.TL.Updates.TLState'.

I think the method

SendRequestAsync

is called concurrently in sending message and getting incoming message and it causes error

knocte commented 5 years ago

Hey @derodevil I've committed a fix to an infinite loop in master branch: 60a3c6235792163e9c74e9c24b1ca7800a220ce2 .

Do you mind updating to use latest master (not sure when the new version will hit nuget.org though, use sources for now)? If after that you keep having this issue please reopen this bug.