Is there a way to set the value of how long the thread should (maximize) be alive when the thread starts?
Speaking differently with "pseudo-code", there is something like this:
Thread t = new Thread(); t.start(); t.abort_after_x_seconds(30);
due to which the stream is interrupted if it has lived for more than 30 seconds.
Edit: I still can't get it to work, which I originally had:
while(true) { if(...) { Thread t = new Thread(new ThreadStart(startMethod)); t.start(); } Thread.sleep(...); }
the problem is that sometimes the threads will hang (I do not implement what the threads do, so I donβt know exactly why (this is a school project, we are noobs when organizing)), so I want to kill these threads. I tried using Tasks and CancellationTokens, as in the examples below, but when the task hangs it cannot check if a cancellation request has occurred.
source share