mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Adds a function to allow the app to terminate a loop and close the client.
This commit is contained in:
parent
f30dc2da43
commit
57b804e15a
|
|
@ -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()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue