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 Session _session;
private List<TLDcOption> dcOptions; private List<TLDcOption> dcOptions;
private TcpClientConnectionHandler _handler; private TcpClientConnectionHandler _handler;
private bool _looping;
public delegate void UpdatesEvent (TelegramClient source, TLAbsUpdates updates); public delegate void UpdatesEvent (TelegramClient source, TLAbsUpdates updates);
public delegate void ClientEvent(TelegramClient source); public delegate void ClientEvent(TelegramClient source);
@ -117,12 +118,18 @@ namespace TLSharp.Core
} }
} }
public void Close()
{
_looping = false;
}
public async Task MainLoopAsync(int timeslicems) public async Task MainLoopAsync(int timeslicems)
{ {
logger.Trace("Entered loop"); logger.Trace("Entered loop");
var lastPing = DateTime.UtcNow; var lastPing = DateTime.UtcNow;
await SendPingAsync(); await SendPingAsync();
for (;;) _looping = true;
while (_looping)
{ {
try try
{ {
@ -415,7 +422,7 @@ namespace TLSharp.Core
return false; return false;
return _transport.IsConnected; return _transport.IsConnected;
} }
} }
public void Dispose() public void Dispose()
{ {