Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error TaskCanceledException #78

Open
JoewAlabel opened this issue Jun 6, 2024 · 1 comment
Open

Error TaskCanceledException #78

JoewAlabel opened this issue Jun 6, 2024 · 1 comment

Comments

@JoewAlabel
Copy link

I am gettiong this error after send one command: help

Unhandled exception. System.Threading.Tasks.TaskCanceledException: A task was canceled.
at PrimS.Telnet.ByteStreamHandler.IsWaitForIncrementalResponse(DateTime rollingTimeout)
at PrimS.Telnet.ByteStreamHandler.IsResponseAnticipated(Boolean isInitialResponseReceived, DateTime endInitialTimeout, DateTime rollingTimeout)
at PrimS.Telnet.ByteStreamHandler.ReadAsync(TimeSpan timeout)
at JoewAlabelTelnet.Program.RunCommand()
at System.Threading.Tasks.Task.<>c.b__128_1(Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

The difference is my telnet do not send any character like $ or >
It just appears the blinking underline to write text.

The telnet runs only locally so not need login too.
Here my full code:

private static string data;
private static Client client;

static async Task Main(string[] args)
{       
    using (client = new Client(args[0], int.Parse(args[1]), new CancellationToken()))
    {
        data = await client.ReadAsync();
        Console.WriteLine(data);

        RunCommand();
    }
}

static async void RunCommand()
{
    await client.WriteAsync(Console.ReadLine());
    data = await client.ReadAsync();
    Console.WriteLine(data);
    RunCommand();
}

I can see the msg after I connect but I got error after try using any command.
Can anyone help me, please?
Thanks!

@9swampy
Copy link
Owner

9swampy commented Jul 8, 2024

You didn't await the RunCommand so as soon as that line executes the Main method continues, the CancellationToken falls out of scope and hence you get the error. You'd have neded to await RunCommand();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants