CancellationToken Test
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user