I have this 3rd party library that exposes a Connect
method, which is not time-bound in any way shape or form. If it fails it raises an exception after many many minutes. Peeking in looks like it's using TcpClient
to make the calls.
What's the elegant way to time-bound a call to 3rdPartyLibObject.Connect()
in my code?
Of course, I can always just Task.Run()
my way into it —
var task = Task.Run(() =>
{
return IHopeYouReNotInAHurryMethod();
});
bool completed = task.Wait(5000);
but that seems to be frowned upon for anything but CPU pegging work, and this is definitely not it.