Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

thread was being aborted

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DC Gringo - 21 Jul 2005 21:51 GMT
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
Daniel Walzenbach - 21 Jul 2005 23:10 GMT
Gringo,

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

Let me know if this works for you.

  Daniel Walzenbach

>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:
[quoted text clipped - 72 lines]
> _____
> DC G
DC Gringo - 21 Jul 2005 23:24 GMT
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

> Gringo,
>
[quoted text clipped - 80 lines]
>> _____
>> DC G
Brock Allen - 22 Jul 2005 01:53 GMT
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
[quoted text clipped - 67 lines]
> _____
> DC G
Bruce Barker - 22 Jul 2005 02:21 GMT
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)

>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:
[quoted text clipped - 72 lines]
> _____
> DC G

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.