【问题标题】:Getting Thread was being aborted in asp获取线程在 asp 中被中止
【发布时间】:2015-12-29 22:24:15
【问题描述】:

我正在尝试在 ASP 页面中创建一个非常大的文本文件,但我得到了线程被中止的异常,并且我没有使用 Response.Redirect/Server。 你知道我为什么会得到这个吗?或者您能否告诉我另一种在 ASP 中创建大文本文件的方法?

引起我注意的是这个异常并不总是发生,我第一次运行它并且它工作但接下来我运行它的 3 或 4 次异常发生然后它再次工作。

GetTextFileName(Byval filename as String) as Boolean
    If Directory.Exists(Server.MapPath("./Report/E005/Texts")) Then
        Directory.Delete(Server.MapPath("./Report/E005/Texts"), True)
        Directory.CreateDirectory(Server.MapPath("./Report/E005/Texts"))
    Else
        Directory.CreateDirectory(Server.MapPath("./Report/E005/Texts"))
    End If
    While continue
        cmd.Parameters.Clear()
        cmd.Parameters.Add(New OracleParameter("p_minus", minus))
        cmd.Parameters.Add(New OracleParameter("p_max", max))
        p = New OracleParameter("p_report", OracleType.Cursor)
        p.Direction = ParameterDirection.Output
        cmd.Parameters.Add(p)
        dt = ejecutar.consulta(cmd, "Report").Tables(0)

        If dt.Rows.Count > 0 Then
            'Writes File
            Dim x As String = Me.GenerateTXT(dt, FolderRoute, fileName & fileCounter.ToString & ".txt", minus)
            dt = Nothing
        ElseIf minus <= 1 Then
            'There was not data
            MsgBox1.ShowMessage("There was not data")
            continue = False
        Else
            'There was not data but I'm not in first page, so I finished data
            continue = False
        End If
        minus += 100000
        max += 100000
        FileCounter += 1
    End While
    'Generate ZIP
    If File.Exists(Server.MapPath(ZipFolder) & ZipName & ".zip") Then
        File.Delete(Server.MapPath(ZipFolder) & ZipName & ".zip")
    End If
    zip.AddDirectory(Server.MapPath(RouteFolder))
    zip.Save(Server.MapPath(ZipFolder) & ZipName & ".zip")
    filename = Server.MapPath(ZipFolder) & ZipName & ".zip"
    Return True
 End Function

【问题讨论】:

  • 有人可能会提供帮助,但我们需要更多详细信息/代码才能知道发生了什么。另外,什么是“大”文本文件?
  • 我正在尝试在文本文件中写入查询结果,查询带来了 600000 行
  • 我添加了一些我也使用的代码
  • 多长时间后你会得到线程中止异常?通常,在 IIS 中,在 IIS 终止请求并重新启动进程之前允许处理请求的时间有限制(并且您会得到线程中止的异常)。还要确保您没有耗尽内存,IIS 还会监视内存利用率并在消耗过多时终止您的进程。一般来说,Web 请求可能不是像这样进行批处理的最佳场所。

标签: asp.net


【解决方案1】:

我继续调试,发现我删除和创建文件夹的部分是引发异常的部分。我想是这样,因为我评论了那部分并且异常没有再次触发。 但我不知道为什么会出现问题......

【讨论】:

    猜你喜欢
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    相关资源
    最近更新 更多