There is a 3rd-party code from the library which "hangs" waiting for somewhere in the work with the network. CancellationToken no support, no timeout. I run it through:

 Task.Run(() => FooWith3rdPart()); 

The first idea was to make hara-kiri:

 void FooWith3rdPart() { new Timer(Thread.CurrentThread.Abort, null, 1000, -1); // here stuck code } 

But in netcore there is no CurrentThread.Abort .

What other options are there?

  • 3
    A good and correct way is to make a wrapper around this as a separate application. Now, in case it hangs, you can always nail the application. - KoVadim
  • You do not have to run code that you don’t trust in your process. Because the code running in your process can do everything. For example, stop all threads or crash. - VladD
  • @VladD the author does not seem to express any distrust :). The library simply does not support cancellation and timeouts, but according to the requirements such a need exists. Hence the question. - andreycha
  • @andreycha: Well, if the code hangs, then it’s poorly debugged, so I wouldn’t trust it. Maybe, if you believe the author, the code will not deliberately harm, but it may well damage unconsciously. - VladD
  • @andreycha: Well, if the library is good, but simply does not support cancellation / timeouts, then it is not suitable for the project, and you need to look for a new one or write your own. - VladD

0