From 57b804e15a145b6495f07cf894c420a640ac89fd Mon Sep 17 00:00:00 2001 From: Paulo Rogerio Panhoto Date: Tue, 27 Feb 2018 16:42:10 -0300 Subject: [PATCH] Adds a function to allow the app to terminate a loop and close the client. --- TLSharp.Core/TelegramClient.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 2f80552..b0d84af 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -31,6 +31,7 @@ namespace TLSharp.Core private Session _session; private List dcOptions; private TcpClientConnectionHandler _handler; + private bool _looping; public delegate void UpdatesEvent (TelegramClient source, TLAbsUpdates updates); public delegate void ClientEvent(TelegramClient source); @@ -117,12 +118,18 @@ namespace TLSharp.Core } } + public void Close() + { + _looping = false; + } + public async Task MainLoopAsync(int timeslicems) { logger.Trace("Entered loop"); var lastPing = DateTime.UtcNow; await SendPingAsync(); - for (;;) + _looping = true; + while (_looping) { try { @@ -415,7 +422,7 @@ namespace TLSharp.Core return false; return _transport.IsConnected; } - } + } public void Dispose() {