Re: Stop aborting my thread!

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jerry Camel (rlrcstr_at_msn.com)
Date: 02/26/04


Date: Wed, 25 Feb 2004 19:36:57 -0500

Is that the proper way to terminate the file transfer, or should I be using something else? (Response.Close ?)
Or would a Response.Flush do the same thing?

I've worked around it by moving the response.end call to the end of the procedure, but I'm a bit new to web dev, so I want to learn the proper methods. Thanks.

Jerry
  "bruce barker" <nospam_brubar@safeco.com> wrote in message news:ud$P0y$%23DHA.2072@TK2MSFTNGP11.phx.gbl...
  Response.End is implemented as a thread abort, so this is expected behavior.

  -- bruce (sqlwork.com)

    "Jerry Camel" <rlrcstr@msn.com> wrote in message news:ug8SVE##DHA.2216@TK2MSFTNGP10.phx.gbl...
    The following code throws a "Thread was being aborted" exception at the Response.End line. Even if I catch the exception, the code that follows is never executed. (Because the thread was being aborted...?) What does this mean? Why is it happening? How do I fix it? I've tried everything I can think of. I've wrapped all the code in try blocks, but the thread exception is the only one being thrown. Please help... Thanks.

    Jerry

    sCommand = "SELECT * FROM FD_Files " & _
               "WHERE (HashName = '" & e.CommandArgument() & "')"

    Dim daFiles As New SqlDataAdapter(sCommand, sqlCnxn)
    Dim dsFiles As New DataSet()
    daFiles.Fill(dsFiles, "FD_Files")
    Dim dr As DataRow = dsFiles.Tables("FD_Files").Rows(0)
    Dim fStream As FileStream
    Dim bytesToGo As Long
    Dim bytesRead As Long
    Dim byteBuffer(2048) As Byte

    fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
                             FileAccess.Read, FileShare.Read)
    bytesToGo = fStream.Length
    Response.BufferOutput = False
    Response.Clear()
    Response.ClearContent()
    Response.ClearHeaders()
    Response.ContentType = "application/octet-stream"
    Response.AppendHeader("Content-Disposition", "attachment; filename=""" & dr("FileName") & """")
    Response.AppendHeader("Content-Length", fStream.Length)
    Response.Flush()

    While (bytesToGo > 0)
       If (Response.IsClientConnected) Then
          bytesRead = fStream.Read(byteBuffer, 0, 2048)
          Response.OutputStream.Write(byteBuffer, 0, bytesRead)
          Response.Flush()
          bytesToGo -= bytesRead
       Else
          bytesToGo = -1
       End If
    End While

    fStream.Close()
    Response.End()


Quantcast