I have a (possibly) lengthy operation a to which I want to impose a limit time constraint t (in milliseconds). If operation a takes less than t milliseconds to complete then I return the answer from operation a; otherwise I want to abort the operation and return a proper error code stating that the time limit constraint was exceeded.
How can I accomplish this in C#? If you have other ideas that are language agnostic feel free to share?