Background
We have a piece of programmable hardware here at work that we integrate into almost all of our systems. This piece of hardware came with a native Windows DLL (for which we do not have the source code) as well as a wrapper to said library. This wrapper is responsible only for marshalling the calls to the native API up to the .NET layer and nothing more. Therefore, we use this wrapper in order to make the calls to the native API.
This piece of programmable hardware is physically integrated into our product in a very problematic way. The piece of hardware sits in the product in such a way that every once in a while the USB cable gets cut in half... (don't ask) The problem is that the cable tends to get cut in half when we are deep into the native API. When this happens, the caller will not return from the native API function. Below is a snippet of what the call looks like via the wrapper:
public static UInt32 Wrap(UInt32 configval, Int32 channum, IntPtr handleval)
{
if (IntPtr.Size == 4)
return Native32(configval, channum, handleval);
else
return Native64(configval, channum, handleval);
}
Question
Is there a general method of making sure we don't hang inside of the API?
I already know that I can just start a task, and wait for it with a timeout (just resume if it times out). This method works, but is there any other way of doing this? I have no control whatsoever of what goes on inside the API.