It is possible to stop background client before finish process?
Hello! In samples we do something like this:
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
Td.Client.Run();
}).Start();
This client will work from behind for the entire duration of the program. Until its completion. If I want to run it, download something, then stop, and run it again later, then how should I do it?
I don't want it to work from the back for the entire duration of the program. I want to stop it and run it as needed.
If we call Td.Client.Run() again, we will get an error (Receive must not be called simultaneously from two different threads...).
I use C# wrapper.
In the latest TDLib versions method Client::Run is a static method and needs to be called only once before the first Client is created on a separate dedicated thread. The method processes updates and request responses from all TDLib instances and never returns. It doesn't consume any noticeable resources when there are no clients, so there are no reasons to stop the thread.
To close a client you need to use the method TdApi.Close and wait for TdApi.updateAuthorizationState with TdApi.AuthorizationStateClosed.