Adds a function to allow the app to terminate a loop and close the client.

This commit is contained in:
Paulo Rogerio Panhoto 2018-02-27 16:42:10 -03:00
parent f30dc2da43
commit 57b804e15a

View file

@ -31,6 +31,7 @@ namespace TLSharp.Core
private Session _session;
private List<TLDcOption> 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()
{