您可以在单独的线程中运行该操作,然后在线程连接操作上设置超时:
using System.Threading;class Program { static void DoSomething() { try { // your call here... obj.PerformInitTransaction(); } catch (ThreadAbortException) { // cleanup pre, if needed... } } public static void Main(params string[] args) { Thread t = new Thread(DoSomething); t.Start(); if (!t.Join(TimeSpan.FromSeconds(30))) { t.Abort(); throw new Exception("More than 30 secs."); } }}


