CancellationToken Test

This commit is contained in:
2023-12-20 16:20:32 +09:00
parent 4b4d64331e
commit e10ff8bade
5 changed files with 100 additions and 1 deletions

View File

@@ -33,14 +33,21 @@ namespace TelnetCommunicator
private void InitInstance()
{
_tap = new TAP("200.200.200.123", 23);
_tap.ErrorHandler -= On_Received;
_tap.ErrorHandler += On_Received;
}
private async void btnStatus_Click(object sender, RoutedEventArgs e)
{
string response = await _tap.SendMessage("STA");
tbMessage.AppendText(GetInfo(response) + Environment.NewLine);
//tbMessage.AppendText(GetInfo(response) + Environment.NewLine);
tbMessage.AppendText(response + Environment.NewLine);
tbMessage.ScrollToEnd();
if (CheckConnectionError(response))
{
InitInstance();
}
}
private void On_Received(object sender, Exception e)
@@ -52,6 +59,18 @@ namespace TelnetCommunicator
}));
}
private bool CheckConnectionError(string message)
{
string[] lines = message.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
if (line.IndexOf("trouble") > 0)
return true;
}
return false;
}
private string GetInfo(string message)
{
string[] lines = message.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);