Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > thread was being aborted

Reply
Thread Tools

thread was being aborted

 
 
DC Gringo
Guest
Posts: n/a
 
      07-21-2005
I have some code that creates and writes to an excel file. Right as I
response.end() to avoid HTML in the Excel document, I get an exception:

---------------

An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()

-----------------

Here's my code


Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")

'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))

'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()

Catch ex As Exception
ExceptionManager.Publish(ex)
End Try

End Sub



Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Try

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next

Response.Write(vbCrLf)

'Output Data

For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next

Catch ex As Exception
ExceptionManager.Publish(ex)

End Try

End Function

_____
DC G


 
Reply With Quote
 
 
 
 
Daniel Walzenbach
Guest
Posts: n/a
 
      07-21-2005
Gringo,

you might want to replace Response.End() with Response.Flush.

Let me know if this works for you.

Daniel Walzenbach


"DC Gringo" <> schrieb im Newsbeitrag
news:...
>I have some code that creates and writes to an excel file. Right as I
>response.end() to avoid HTML in the Excel document, I get an exception:
>
> ---------------
>
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
>
> -----------------
>
> Here's my code
>
>
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
>
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
>
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
>
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
>
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
>
> End Sub
>
>
>
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
>
> Try
>
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
>
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
>
> Response.Write(vbCrLf)
>
> 'Output Data
>
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
>
> Catch ex As Exception
> ExceptionManager.Publish(ex)
>
> End Try
>
> End Function
>
> _____
> DC G
>



 
Reply With Quote
 
DC Gringo
Guest
Posts: n/a
 
      07-21-2005
Daniel,

Sorry, it didn't work. I didn't get the error, but the HTML returned to the
Excel file. Putting the response.flush() after the response.close() or vice
versa still generated the error.

_____
DC G


"Daniel Walzenbach" <> wrote in message
news:%...
> Gringo,
>
> you might want to replace Response.End() with Response.Flush.
>
> Let me know if this works for you.
>
> Daniel Walzenbach
>
>
> "DC Gringo" <> schrieb im Newsbeitrag
> news:...
>>I have some code that creates and writes to an excel file. Right as I
>>response.end() to avoid HTML in the Excel document, I get an exception:
>>
>> ---------------
>>
>> An attempt to log the following error
>> failed:System.Threading.ThreadAbortException: Thread was being aborted.
>> at System.Threading.Thread.AbortInternal()
>> at System.Threading.Thread.Abort(Object stateInfo)
>> at System.Web.HttpResponse.End()
>>
>> -----------------
>>
>> Here's my code
>>
>>
>> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
>> System.EventArgs)
>>
>> Try
>> Dim ds As New DataSet
>> Dim da As New SqlDataAdapter(Session("savedShasSql"),
>> connection1.conString)
>> da.Fill(ds, "ShasExcel")
>> Dim dt As DataTable = ds.Tables("ShasExcel")
>>
>> 'This code was dumping html into the spreadsheet
>> 'Response.ContentType = "application/ms-excel"
>> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
>> 'Response.Write(ConvertDtToTDF(dt))
>>
>> 'This is the new code
>> Response.ContentType = "application/ms-excel"
>> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
>> Response.Clear()
>> Response.Write(ConvertDtToTDF(dt))
>> Response.End()
>>
>> Catch ex As Exception
>> ExceptionManager.Publish(ex)
>> End Try
>>
>> End Sub
>>
>>
>>
>> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
>>
>> Try
>>
>> Dim dr As DataRow, ary() As Object, i As Integer
>> Dim iCol As Integer
>>
>> 'Output Column Headers
>> For iCol = 0 To dt.Columns.Count - 1
>> Response.Write(dt.Columns(iCol).ToString & vbTab)
>> Next
>>
>> Response.Write(vbCrLf)
>>
>> 'Output Data
>>
>> For Each dr In dt.Rows
>> ary = dr.ItemArray
>> For i = 0 To UBound(ary)
>> Response.Write(ary(i).ToString & vbTab)
>> Next
>> Response.Write(vbCrLf)
>> Next
>>
>> Catch ex As Exception
>> ExceptionManager.Publish(ex)
>>
>> End Try
>>
>> End Function
>>
>> _____
>> DC G
>>

>
>



 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      07-22-2005
Yes, this is the way ASP.NET attempts to insure that the processing halts
for the current request -- they throw a ThreadAbortException. Sort of odd,
eh? Well, the magic with a ThreadAbortException is that if you put a try/catch
around it, it still gets thrown outside your catch -- they're doing this
so you don't catch their attempt to terminate the request. So, in short,
it's just how it works.

-Brock
DevelopMentor
http://staff.develop.com/ballen



> I have some code that creates and writes to an excel file. Right as I
> response.end() to avoid HTML in the Excel document, I get an
> exception:
>
> ---------------
>
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being
> aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
> -----------------
>
> Here's my code
>
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e
> As System.EventArgs)
>
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition",
> "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition",
> "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Sub
>
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
>
> Try
>
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
>
> 'Output Data
>
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
>
> End Function
>
> _____
> DC G




 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      07-22-2005
a Response.End() does a flush, then kills the current thread (to stop
continued processing). ignore the thread abort in your catch

-- bruce (sqlwork.com)




"DC Gringo" <> wrote in message
news:...
>I have some code that creates and writes to an excel file. Right as I
>response.end() to avoid HTML in the Excel document, I get an exception:
>
> ---------------
>
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
>
> -----------------
>
> Here's my code
>
>
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
>
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
>
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
>
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
>
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
>
> End Sub
>
>
>
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
>
> Try
>
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
>
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
>
> Response.Write(vbCrLf)
>
> 'Output Data
>
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
>
> Catch ex As Exception
> ExceptionManager.Publish(ex)
>
> End Try
>
> End Function
>
> _____
> DC G
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread was being aborted =?Utf-8?B?eHNsdXNlcg==?= ASP .Net 2 11-17-2005 08:25 PM
Thread was being aborted Loui Mercieca ASP .Net 4 09-04-2005 12:38 PM
Thread was being aborted enahar ASP .Net 6 03-09-2005 12:52 AM
Thread was being aborted thrown for background thread (win2003 ser =?Utf-8?B?Sm9oYW5uYQ==?= ASP .Net 3 10-15-2004 01:35 PM
Thread was being aborted in win2003 server. Back ground thread reading MS access database, no redirects or transfers. Johanna ASP .Net 0 10-13-2004 01:32 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57