任务超时退出的方法 C#

        private static bool ImportTaskTimeout(Action method, int hours)
        {
            try
            {
                var task = Task.Run(() => method());
                if (task.Wait(TimeSpan.FromHours(hours)))
                    return task.IsCompleted;
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }

超出时间方法退出。防止卡住。