I write programm which is looking the specific chat for specific messages, if it was found then forward them to another chat. I want to solve troubles with internet connection, after connection is lost more then 1-2 minutes WTelegramCLient doesnt reconnect automaticly. I tried to increase MaxAutoReconnects and tried to catch ReactorError object on client.OnUpdate event, but nothing is changing. After connection is lost client.OnUpdate is not recieved the ReactorError object at all if the there is no internet longer then 5 minutes. I handled SocketException to autoreconnect but its doesnt work sometimes too. How can i handle with it in a proper way?
Program.cs
private static System.Timers.Timer timer;
private static TClient client;
private static void SetTimer()
{
timer = new System.Timers.Timer(3000);
timer.Elapsed += OnTimer_Elapsed;
}
private static void OnTimer_Elapsed(object sender, ElapsedEventArgs e)
{
timer.Stop();
Connect();
}
private async static void Connect()
{
client = new TClient();
try
{
await client.Connect();
await client.CheckOldMessages();
}
catch (SocketException sEx)
{
client.Dispose();
timer.Start();
}
}
TClient.cs
...
private Client client;
...
public async Task Connect() => await client.LoginUserIfNeeded();
private async Task<object> Client_OnUpdate(IObject arg)
{
if (arg is not UpdatesBase updates)
return null;
updates.CollectUsersChats(users, chats);
foreach (Update update in updates.UpdateList)
{
switch (update)
{
case UpdateNewMessage unm when unm.message.Peer.ID == typicalDonetskID:
await ForwardMessage(unm.message);
break;
}
}
return null;
}