Understanding a 'thread was being aborted/mscorlib' exception

Discussion in 'ASP .Net' started by darrel, Mar 9, 2006.

  1. darrel

    darrel Guest

    I have a function that calls a class that writes a dataset that I've passed
    to it out as an excel spreadheet and returns it to the browser:

    my function
    try
    makeExcelFile(mydataset)
    catch
    response write the exceptions
    end try
    end function

    This works. However, at the very bottom of my excel spreadsheet that gets
    generated, it prints out the CATCH response write from my function:

    Thread was being aborted.
    mscorlib

    From a bit of googling, I can't quite tell if that's an error, or just a
    normal response and that I probably should just check for that specific
    response and not bother writing it out.

    I'm also a bit confused as to why it's writing the error the spreadsheet.
    Should the spreadsheet be written, that function returns the exception, then
    my function catch it and, in turn, write the exception back to the screen?

    -Darrel
    darrel, Mar 9, 2006
    #1
    1. Advertising

  2. darrel

    darrel Guest

    Oh, and here's the function that is apparently returning that exception:

    Public Shared Sub Convert(ByVal ds As DataSet, ByVal response As
    HttpResponse)
    'first let's clean up the response.object
    response.Clear()
    response.Charset = ""
    'set the response mime type for excel
    response.ContentType = "application/vnd.ms-excel"
    'create a string writer
    Dim stringWrite As New System.IO.StringWriter
    'create an htmltextwriter which uses the stringwriter
    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
    'instantiate a datagrid
    Dim dg As New DataGrid
    'set the datagrid datasource to the dataset passed in
    dg.DataSource = ds.Tables(0)
    'bind the datagrid
    dg.DataBind()
    'tell the datagrid to render itself to our htmltextwriter
    dg.RenderControl(htmlWrite)
    'all that's left is to output the html
    response.Write(stringWrite.ToString)
    response.End()
    End Sub

    -darrel
    darrel, Mar 9, 2006
    #2
    1. Advertising

  3. darrel

    darrel Guest

    > From the blog of a friend:
    >
    > "This problem occurs when calling a Response.Redirect() or a
    > Server.Transfer() within a Try...Catch block. This is because the
    > Response.Redirect() method will call the Response.End() method and the
    > Response.End() method will call the Abort() method of the running thread."


    Thanks. I saw that too. However, neither of the functions are calling a
    server transfer or response.redirect. It IS using a bunch of other
    response.* calls, though (see my other reply) so perhaps one of those is the
    culprit.

    AFAICT, there's no actual error, as all the data is rendered.

    -Darrel
    darrel, Mar 9, 2006
    #3
  4. darrel

    Steven Spits Guest

    "darrel" wrote:

    > This works. However, at the very bottom of my excel spreadsheet that gets
    > generated, it prints out the CATCH response write from my function:
    >
    > Thread was being aborted.
    > mscorlib


    From the blog of a friend:

    "This problem occurs when calling a Response.Redirect() or a
    Server.Transfer() within a Try...Catch block. This is because the
    Response.Redirect() method will call the Response.End() method and the
    Response.End() method will call the Abort() method of the running thread."

    Steven

    - - -
    Steven Spits, Mar 9, 2006
    #4
  5. darrel

    Steven Spits Guest

    "darrel" wrote:

    > Oh, and here's the function that is apparently returning that exception:


    Based on my previous post, this line is to blame:

    > response.End()


    Steven

    - - -
    Steven Spits, Mar 9, 2006
    #5
  6. darrel

    darrel Guest


    > Based on my previous post, this line is to blame:
    >> response.End()


    Ah! Great. Mystery solved!

    Thanks!

    -Darrel
    darrel, Mar 9, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elliot M. Rodriguez
    Replies:
    1
    Views:
    2,919
    Elliot M. Rodriguez
    Jan 22, 2004
  2. Stephen Miller
    Replies:
    3
    Views:
    3,949
    Stephen Miller
    Jul 2, 2004
  3. Johanna
    Replies:
    0
    Views:
    594
    Johanna
    Oct 13, 2004
  4. =?Utf-8?B?Sm9oYW5uYQ==?=
    Replies:
    3
    Views:
    1,943
    =?Utf-8?B?Sm9oYW5uYQ==?=
    Oct 15, 2004
  5. =?Utf-8?B?VC4=?=

    Error - mscorlib : Thread was being aborted.

    =?Utf-8?B?VC4=?=, Aug 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,774
    Brock Allen
    Aug 13, 2005
Loading...

Share This Page