程序中如何处理超时问题

来源:互联网 发布:上海音乐学院网络报名 编辑:程序博客网 时间:2024/06/10 18:00
1、SQL 存储过程中,设置超时时间的方法:

--设置存储过程执行时间5秒

SET Lock_TimeOut 5000;


2、C#代码访问数据库,设置超时时间:

1)SqlConnection中设置超时时间的方法:SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS ;Integrated security=sspi;connection timeout=5");

2)SqlCommand中设置超时时间的方法:

            SqlCommand cmd = new SqlCommand("select * from tablename");

            cmd.CommandTimeout = 5;


3、C#代码中,A函数同步调用B函数,如果B函数在5秒内仍未执行完毕,那么就认为B函数执行失败:

http://stackoverflow.com/questions/3684346/call-method-b-if-method-a-is-not-called-for-more-than-n-seconds



4、C#代码中,A函数异步调用B函数,如果B函数在5秒内未执行完毕,那么就认为B函数执行失败:
http://www.codeproject.com/Articles/37365/Calling-Method-Asynchronously-With-A-Timeout


原创粉丝点击