/// <summary> /// Limex: timout function. Usage: /// </summary> /// <typeparam name="T"></typeparam> /// <param name="F"></param> /// <param name="Timeout"></param> /// <param name="Completed"></param> /// <returns></returns> public static T Limex<T>(Func<T> F, int Timeout, out bool Completed) { T result = default(T); Thread thread = new Thread(() => result = F()); thread.Start(); Completed = thread.Join(Timeout); if (!Completed) thread.Abort(); return result; } // Overloaded method, for cases when we don't // need to know if the method was terminated public static T Limex<T>(Func<T> F, int Timeout) { bool Completed; return Limex(F, Timeout, out Completed); }
283300cookie-checkC# Function Timeouts