Tag: 超时

用于将.NET应用程序修复为SQL Server超时问题并缩短执行时间的清单

用于缩短.NET代码和SQL Server之间执行时间的核对表。 任何从基本到奇怪的解决方案的东西都值得赞赏。 码: 更改avgbody命令和连接的默认超时。 使用存储过程调用而不是avgbody的内联sql语句。 使用Jay Shepherd的 Activity监视器查找阻塞/锁定。 SQL Server: 请注意AlexCuse在存储过程中的参数嗅探。 谨防Martin Clarke动态增长数据库。 使用Profiler查找BradO需要更长时间100毫秒的任何查询/存储过程。 avgbody增加事务超时。 avgbody将动态存储过程转换为静态过程。 查看Jay Shepherd对服务器的忙碌程度。

ADO.NET的SqlCommand.CommandTimeout如何工作?

考虑一个存储过程,该过程在60秒内更新某些行而不使用事务。 我们将ADO.NET的SqlCommand.Timeout设置为30秒。 SqlCommand.Timeout = 30; 当超时发生在30秒时,存储过程是否会继续在数据库服务器中运行? 服务器如何将此信息传达给客户端?

.net异步套接字超时检查线程安全

http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx 从上面的msdn示例开始,我正在尝试编写一个超时检查,它将关闭非活动的客户端套接字并释放资源。 这就是我想出的。 但我不确定它是否完全是线程安全的,如果有更好的方法可以做到这一点。 我希望有人能给出一些建议。 void IO_Completed(object sender, SocketAsyncEventArgs e) { if (e.SocketError != SocketError.Success) { CloseClientSocket(e); return; } if (1 0) if (!token.Socket.SendAsync(e)) ProcessSend(e); else CloseClientSocket(e); } void ProcessSend(SocketAsyncEventArgs e) { AsyncUserToken token = (AsyncUserToken)e.UserToken; if (!token.Socket.ReceiveAsync(e)) ProcessReceive(e); } TimeoutCheck将每20秒执行一次。 allReadWriteArgs是一个包含所有SocketAsyncEventArgs的数组。 关闭套接字后,将使用SocketError.OperationAborted调用IO_Completed。 void TimeoutCheck(object state) { AsyncUserToken token; int timeout = Environment.TickCount – 20000; […]

锁定超时模式

lock使用这种模式 if(Monitor.Enter(lock)) try { … } finally { Monitor.Exit(lock); } // using this style to reduce post “height” 如果我们不想等待无限,我们可以提供超时 if(!Monitor.TryEnter(lock, timeout)) throw new TimeoutException(); try { … } finally { Monitor.Exit(lock); } 我有方法,方法必须在开始做任何事情之前获得多个锁。 这看起来很糟糕: if(!Monitor.TryEnter(lockA, timeout)) throw new TimeoutException(); try { if(!Monitor.TryEnter(lockB, timeout)) throw new TimeoutException(); try { if(!Monitor.TryEnter(lockC, timeout)) throw new TimeoutException(); try { […]

SmtpClient超时不起作用

我已经设置了SmtpClient类的Timeout属性,但它似乎不起作用,当我给它一个1毫秒的值时,执行代码时超时实际上是15秒。 我从msdn获取的代码。 string to = “jane@contoso.com”; string from = “ben@contoso.com”; string subject = “Using the new SMTP client.”; string body = @”Using this new feature, you can send an e-mail message from an application very easily.”; MailMessage message = new MailMessage(from, to, subject, body); SmtpClient client = new SmtpClient(“1.2.3.4”); Console.WriteLine(“Changing time out from {0} to […]

如何将DataAdapter的超时时间增加到3分钟?

当我使用以下方法执行查询时,我得到超时。 所以我的问题是:如何将超时设置为180秒? 我正在使用连接来使用queryresult填充dataSet。 internal static DataSet executeQuery(string queryString) { // #connection DataSet dataSet = new DataSet(); string connectionString = Connection.connectionStringSQL01NavProvider(); OleDbConnection connection = new OleDbConnection(connectionString); OleDbDataAdapter adapter = new OleDbDataAdapter(queryString, connectionString); // Open the connection and fill the DataSet. connection.Open(); try { adapter.Fill(dataSet); DataTable dt = new DataTable(); dt = dataSet.Tables[0]; DataRow dr; try { […]

为什么asp.net会话比其超时更早到期?

我有一个Asp.net网络服务。 它有方法M1。 M1为每个会话创建一个文件夹。 会话过期后,我使用以下代码删除global.asax中的该文件夹。 void Session_End(object sender, EventArgs e) { try { System.IO.DirectoryInfo dirMyPacksFolder = new System.IO.DirectoryInfo(Utilities.getMyPacksFolder(Session)); //dirMyPacksFolder.Parent.CreateSubdirectory(“ended_” + Session.SessionID); if (dirMyPacksFolder.Exists) { dirMyPacksFolder.Delete(true); } } catch (Exception ex) { Utilities.logException(“”, ex); } } 当我在浏览器中打开我的web服务并调用M1时,它正常运行,并且在我设置的超时到期时间删除该文件夹。 但是当我第二次提交webservice的“Invoke”按钮时(在会话超时和文件夹被删除之后),它的会话开始 (创建文件夹)并在我设置的超时之前立即 结束 (删除文件夹) 。 为什么会这样? 如果我为每个方法调用打开一个新窗口(新会话),一切正常。 但是当我第二次点击“调用”按钮时,我遇到了问题。 这类似于同一会话的缓存问题。

C#任务工厂超时

我必须在一个线程中执行一个长进程操作,并继续将结果返回给一个函数。 这是我的代码: Task.Factory.StartNew(() => { try { // long operation which return new ProductEventArgs with a list of product } catch (Exception e) { return new ProductEventArgs() { E = e }; } }).ContinueWith((x) => handleResult(x.Result), TaskScheduler.FromCurrentSynchronizationContext()); 问题实际上我没有超时。 我想放一个计时器,以便返回这样的东西: new ProductEventArgs() { E = new Exception(“timeout”) }; 如果达到超时。 不能使用await / async。 非常感谢 !

查询大表时的连接超时

在从大型表上查询数据时,我遇到了脚本超时的问题。 该表有9,521,457行。 我正在尝试预先形成的查询是: SELECT * FROM `dialhistory` WHERE `customerId` IN (22606536, 22707251, 41598836); 此查询在HeidiSQL上运行没有问题,大约需要171秒并返回434行。 但是当我运行我的C#脚本剂量时,它会在161行之后超时。 16:54:55: Row 1 … 16:54:55: Row 161 16:55:32: Error -> Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 这是代码 public MySqlDatabase(string server, string database, string username, string password) { ConnectionString […]

C#Stream.Read超时

我有这个streamreader: Boolean read = false; while (wline!=”exit”) { while (!read || streamReader.Peek() >= 0) { read = true; Console.Write((char)streamReader.Read()); } wline = Console.ReadLine(); streamWriter.Write(wline+”\r\n”); streamWriter.Flush(); } 如何设置Read()方法的超时? 谢谢