3

I have a specific situation in my dotnet core code that requires me to be able to abort/cancel a thread running third party code that frequently gets stuck in its execution.

I am unable to use the recommended practice of cancellation tokens since the third party code is the offending party.

The offending code is from the ssh.net project and the bug I am trying to avoid/solve is the following one: https://github.com/sshnet/SSH.NET/issues/355

The following (excellent) suggestion would help me but it is made by using the kernel32 dll and I have to make the code work under docker in a Linux environment: Is it possible to abort a Task like aborting a Thread (Thread.Abort method)?

I have looked at the libc specifications in Linux but I have a hard time figuring out what would be the correct implementation on that platform.

ThreadHelper.RunWithAbort(() => {
    Client?.Disconnect();
    Client?.Dispose();
}, TimeSpan.FromSeconds(10));

The code should be able to terminate the third party code if it freezes and not affect the rest of the application or the system itself.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317

0 Answers0