如何在 Visual Studio 中从 IIS 引发错误
当我在 Visual Studio 中运行我的应用程序时。应用程序不会“崩溃”。我在一个发送电子邮件的图书馆项目中有一个计时器。该计时器每 30000.0 调用一次。我在这个计时器中调用一个具有很长逻辑的方法。当我在 Visual Studio 中时,此方法运行良好。问题是当我将应用程序移至 IIS 时。这会导致以下错误:
System.Threading.ThreadAbortException: Subproceso anulado.
en lktec.Sql.SMail.Send()
en lktec.Sql.SAutoRun.SendMailSchedule(Object source, ElapsedEventArgs e)
有时我会遇到类似的错误:
System.Threading.ThreadAbortException: Subproceso anulado.
en SNIReadSyncOverAsync(SNI_ConnWrapper* , SNI_Packet** , Int32 )
en SNINativeMethodWrapper.SNIReadSyncOverAsync(SafeHandle pConn, IntPtr& packet, Int32 timeout)
en System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
en System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
en System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
en System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
en System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
en System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
en System.Data.SqlClient.SqlDataReader.get_MetaData()
en System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
en System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
en System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
en System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
en lktec.Sql.SqlHelper.ExecuteDataSet(String connectionString, String cmdText, SqlParameter[] paras)
en lktec.Sql.SEdmMailRunLogsLevel2.GetItem4(Int32 paramSysNo)
en lktec.Sql.SAutoRun.SendMailSchedule(Object source, ElapsedEventArgs e)
那么,我遇到的问题是为什么在 Visual Studio 中我没有收到此错误?如何让 Visual Studio 引发此错误?我添加了 try-catch,但这没有任何作用。我还添加了写入文件的步骤,以了解它在哪里中断了计时器的执行。它在错误中指定的位置处中断。但是,如果根本没有引发,我该如何在 Visual Studio 中“修复”这个问题呢?这只发生在 IIS 中。
方法工作原理:
SendMailSchedule()
该方法调用 SQL Server 并获取多个信息(Select 语句:7 个独立调用),然后对 Sql Server 的不同表进行插入和更新。
调用方法时,它会获取调度程序中的有效电子邮件列表。它经过一个循环,并在该循环内获取当前信息(触发器)。然后它获取共享触发器 ID 的所有运行信息的列表。然后它检索有效调度信息的列表。该信息与调度程序不同。
然后进入运行信息列表的内循环。在此循环中验证调度程序信息中指定的 crontab 字符串。如果 crontab 字符串匹配;它进行处理以验证开始时间是否具有运行开始时间值。当它被验证时,它会进入 while 循环。该循环将始终为真,直到运行完成。
在 while 循环内;它获取详细运行信息的列表。这有点像运行信息的 2 级。这里它进入另一个内循环。此时,它会验证 2 级开始时间,并匹配它进入另一个遍历电子邮件列表的内部循环。在这个循环中;它还收集用于更新表、插入步骤的历史日志以及发送电子邮件的信息。
方法的结构:
Foreach (...)
{
Foreach (...) [This will go through a daily once]
{
While(true)
{
Foreach(...) [This will go through a list each Hourly until 20th hour it while to false]
{
Foreach(...) [Here is a list of email Loop]
{
SendEmail
}
}
}
}
}
正如我所说,此方法在 Visual Studio 中运行良好,但在 IIS 中不起作用。有没有办法在 Visual Studio 中引发错误?
When I run my application in Visual Studio. The Application doesn't "break". I have a Timer in a library project that sends emails. This timer is called every 30000.0. I call a method within this timer that have a long logic. This method works fine when I am in Visual Studio. The problem is when I move my application to IIS. This causes the following error:
System.Threading.ThreadAbortException: Subproceso anulado.
en lktec.Sql.SMail.Send()
en lktec.Sql.SAutoRun.SendMailSchedule(Object source, ElapsedEventArgs e)
Somethimes I get a similar error :
System.Threading.ThreadAbortException: Subproceso anulado.
en SNIReadSyncOverAsync(SNI_ConnWrapper* , SNI_Packet** , Int32 )
en SNINativeMethodWrapper.SNIReadSyncOverAsync(SafeHandle pConn, IntPtr& packet, Int32 timeout)
en System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
en System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
en System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
en System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
en System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
en System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
en System.Data.SqlClient.SqlDataReader.get_MetaData()
en System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
en System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
en System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
en System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
en lktec.Sql.SqlHelper.ExecuteDataSet(String connectionString, String cmdText, SqlParameter[] paras)
en lktec.Sql.SEdmMailRunLogsLevel2.GetItem4(Int32 paramSysNo)
en lktec.Sql.SAutoRun.SendMailSchedule(Object source, ElapsedEventArgs e)
So, the thing I am having problem is why in Visual Studio I am not getting this error? How can I make Visual Studio raise this error? I have added try-catch and this doesn't do nothing. I also added steps to write into a file to know where it breaks the timer tread. It breaks at the point where it specified in the error. But how can I "fix" this in visual studio if is not raised at all? This only happen in IIS.
How the method work:
SendMailSchedule()
This method call the SQL Server and obtain several information (Select statements: 7 calls independantly) then it does Insert and Update to the Sql Server to different tables.
When method is called it gets a list of validEmail that are in a scheduler. The it goes trough a loop and within this loop it gets the current information (trigger). Then it gets a list of all the Run information that shares Id of the trigger.Then it retrive a list of valid schedule information. This information is different from scheduler.
Then it goes to a inner loop for the Run information list. At this loop validates the crontab string specified in the scheduler information. If crontab string matches; it processed to validate if start time with run start time value. When it is validated it goes into a while loop. this loop will be always true until the Run is completed.
Within the while loop; it gets a list of Detail Run info. This is kinda like a level 2 for Run Info. Here it goes into another inner loop. At this point, it validates Level 2 start time and it matches it gets into another inner loop that goes through an email list. In this loop; it also does gather information for updating the table, inserting historical log of the steps, and sends emails.
Structure of the Method:
Foreach (...)
{
Foreach (...) [This will go through a daily once]
{
While(true)
{
Foreach(...) [This will go through a list each Hourly until 20th hour it while to false]
{
Foreach(...) [Here is a list of email Loop]
{
SendEmail
}
}
}
}
}
Like I said, this method works fine with Visual Studio but it doesn't work with IIS. Is there a way to raise the error in visual studio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论