I have a problem that is surely familiar to many: I'm making a call (to be specific it is Forest.GetCurrentForest()) which, in some circumstances, will fail to work and throw an exception. Not a huge problem, just catch it and deal appropriately. However the call, when it fails, is very slow; it takes 30 seconds to fully finish.
I went looking for a way to call that method but set-up a timeout so we can stop after a shorter time. I found an interesting suggestion here but I'd like a more general solution if I can work it out. That solution is also rather heavy on extras just to get a timeout. I hoped it would be as easy as, say
CallMethodWithTimeout(Delegate method, int timeout)
But I'm not sure something like that is going to work. Any suggestions on doing something like that, or is it just not possible in C# ? We're also stuck using .NET 2.0.
Barring that, I'll take comments on keeping the GetCurrentForest() call from taking 30 seconds to figure out that it isn't happening. Though I would like to know about the feasibility of that general method caller method.