473,666 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

thread was being aborted

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.T hreading.Thread AbortException: Thread was being aborted.
at System.Threadin g.Thread.AbortI nternal()
at System.Threadin g.Thread.Abort( Object stateInfo)
at System.Web.Http Response.End()

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

Here's my code
Public Sub btnShasExcel_On Click(ByVal sender As System.Object, ByVal e As
System.EventArg s)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter( Session("savedS hasSql"),
connection1.con String)
da.Fill(ds, "ShasExcel" )
Dim dt As DataTable = ds.Tables("Shas Excel")

'This code was dumping html into the spreadsheet
'Response.Conte ntType = "applicatio n/ms-excel"
'Response.AddHe ader("Content-Disposition", "inline;filenam e=shas.xls")
'Response.Write (ConvertDtToTDF (dt))

'This is the new code
Response.Conten tType = "applicatio n/ms-excel"
Response.AddHea der("Content-Disposition", "inline;filenam e=shas.xls")
Response.Clear( )
Response.Write( ConvertDtToTDF( dt))
Response.End()

Catch ex As Exception
ExceptionManage r.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.Coun t - 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
ExceptionManage r.Publish(ex)

End Try

End Function

_____
DC G
Nov 19 '05 #1
4 3032
Gringo,

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

Let me know if this works for you.

Daniel Walzenbach
"DC Gringo" <dc******@visio ntechnology.net > schrieb im Newsbeitrag
news:OP******** ******@tk2msftn gp13.phx.gbl...
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.T hreading.Thread AbortException: Thread was being aborted.
at System.Threadin g.Thread.AbortI nternal()
at System.Threadin g.Thread.Abort( Object stateInfo)
at System.Web.Http Response.End()

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

Here's my code
Public Sub btnShasExcel_On Click(ByVal sender As System.Object, ByVal e As
System.EventArg s)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter( Session("savedS hasSql"),
connection1.con String)
da.Fill(ds, "ShasExcel" )
Dim dt As DataTable = ds.Tables("Shas Excel")

'This code was dumping html into the spreadsheet
'Response.Conte ntType = "applicatio n/ms-excel"
'Response.AddHe ader("Content-Disposition", "inline;filenam e=shas.xls")
'Response.Write (ConvertDtToTDF (dt))

'This is the new code
Response.Conten tType = "applicatio n/ms-excel"
Response.AddHea der("Content-Disposition", "inline;filenam e=shas.xls")
Response.Clear( )
Response.Write( ConvertDtToTDF( dt))
Response.End()

Catch ex As Exception
ExceptionManage r.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.Coun t - 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
ExceptionManage r.Publish(ex)

End Try

End Function

_____
DC G

Nov 19 '05 #2
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" <da************ ***@newsgroup.n ospam> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Gringo,

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

Let me know if this works for you.

Daniel Walzenbach
"DC Gringo" <dc******@visio ntechnology.net > schrieb im Newsbeitrag
news:OP******** ******@tk2msftn gp13.phx.gbl...
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.T hreading.Thread AbortException: Thread was being aborted.
at System.Threadin g.Thread.AbortI nternal()
at System.Threadin g.Thread.Abort( Object stateInfo)
at System.Web.Http Response.End()

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

Here's my code
Public Sub btnShasExcel_On Click(ByVal sender As System.Object, ByVal e As
System.EventArg s)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter( Session("savedS hasSql"),
connection1.con String)
da.Fill(ds, "ShasExcel" )
Dim dt As DataTable = ds.Tables("Shas Excel")

'This code was dumping html into the spreadsheet
'Response.Conte ntType = "applicatio n/ms-excel"
'Response.AddHe ader("Content-Disposition", "inline;filenam e=shas.xls")
'Response.Write (ConvertDtToTDF (dt))

'This is the new code
Response.Conten tType = "applicatio n/ms-excel"
Response.AddHea der("Content-Disposition", "inline;filenam e=shas.xls")
Response.Clear( )
Response.Write( ConvertDtToTDF( dt))
Response.End()

Catch ex As Exception
ExceptionManage r.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.Coun t - 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
ExceptionManage r.Publish(ex)

End Try

End Function

_____
DC G


Nov 19 '05 #3
Yes, this is the way ASP.NET attempts to insure that the processing halts
for the current request -- they throw a ThreadAbortExce ption. Sort of odd,
eh? Well, the magic with a ThreadAbortExce ption 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.T hreading.Thread AbortException: Thread was being
aborted.
at System.Threadin g.Thread.AbortI nternal()
at System.Threadin g.Thread.Abort( Object stateInfo)
at System.Web.Http Response.End()
-----------------

Here's my code

Public Sub btnShasExcel_On Click(ByVal sender As System.Object, ByVal e
As System.EventArg s)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter( Session("savedS hasSql"),
connection1.con String)
da.Fill(ds, "ShasExcel" )
Dim dt As DataTable = ds.Tables("Shas Excel")
'This code was dumping html into the spreadsheet
'Response.Conte ntType = "applicatio n/ms-excel"
'Response.AddHe ader("Content-Disposition",
"inline;filenam e=shas.xls")
'Response.Write (ConvertDtToTDF (dt))
'This is the new code
Response.Conten tType = "applicatio n/ms-excel"
Response.AddHea der("Content-Disposition",
"inline;filenam e=shas.xls")
Response.Clear( )
Response.Write( ConvertDtToTDF( dt))
Response.End()
Catch ex As Exception
ExceptionManage r.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.Coun t - 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
ExceptionManage r.Publish(ex)
End Try

End Function

_____
DC G


Nov 19 '05 #4
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" <dc******@visio ntechnology.net > wrote in message
news:OP******** ******@tk2msftn gp13.phx.gbl...
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.T hreading.Thread AbortException: Thread was being aborted.
at System.Threadin g.Thread.AbortI nternal()
at System.Threadin g.Thread.Abort( Object stateInfo)
at System.Web.Http Response.End()

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

Here's my code
Public Sub btnShasExcel_On Click(ByVal sender As System.Object, ByVal e As
System.EventArg s)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter( Session("savedS hasSql"),
connection1.con String)
da.Fill(ds, "ShasExcel" )
Dim dt As DataTable = ds.Tables("Shas Excel")

'This code was dumping html into the spreadsheet
'Response.Conte ntType = "applicatio n/ms-excel"
'Response.AddHe ader("Content-Disposition", "inline;filenam e=shas.xls")
'Response.Write (ConvertDtToTDF (dt))

'This is the new code
Response.Conten tType = "applicatio n/ms-excel"
Response.AddHea der("Content-Disposition", "inline;filenam e=shas.xls")
Response.Clear( )
Response.Write( ConvertDtToTDF( dt))
Response.End()

Catch ex As Exception
ExceptionManage r.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.Coun t - 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
ExceptionManage r.Publish(ex)

End Try

End Function

_____
DC G

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1424
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by my asp.net application. I hope someone could help me with this error that I get in windows 2003 server. This error has not occured with the same application in windows 2000 professional computers that are also lot older and less effective.
3
2482
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by IIS for my asp.net application on win2003 server. This error has not yet occured with the same asp.net application on windows 2000 professional computers that are also lot older and less effective. And this error does not occure if this thread is run by console application. This asp.net gui application starts a background thread that mainly
1
4261
by: Keith F. | last post by:
Hi, I have an asp.net web app that is intermittently throwing "Thread was being aborted." errors in my data access component. This seems to occur when the app is under a heavier than normal load. I don't get any of these errors for days, then I get a bunch all at once. I would have thought if the database call was timing out I would get a timeout error. The server is Win 2003 (under VMware), and hosts multiple asp and asp.net web...
3
3246
by: Keith F. | last post by:
Hi, I have an asp.net web app that is intermittently throwing "Thread was being aborted." errors in my data access component. This seems to occur when the app is under a heavier than normal load. I don't get any of these errors for days, then I get a bunch all at once. I would have thought if the database call was timing out I would get a timeout error. The server is Win 2003 (under VMware), and hosts multiple asp and asp.net web...
1
662
by: Josef K. | last post by:
I've started getting "Thread was being aborted" errors. This errormessage has me puzzled. I'm using the same very simple approach throughout the application, and it works elsewhere: -- my aspx form declares an instance of a data-layer class with form-level scope Protected WithEvents MyDataLayer as DataLayer -- and a new instance of the class is created in Page_Load:
5
495
by: Jimi | last post by:
Hi all, I have a user control which raises an event to the parent page when a person clicks on a link in a datagrid. In the event handler inside the parent page I construct a url to redirect to containing information sent from the datagrid. It all works fine on my local machine but when I send it to the live server I receive "The thread was being aborted" Doing some googling suggested that I use
4
4905
by: Totto | last post by:
Hi, I'm doing a server.transfer from a click event of a button, but an exception is raised with "Thread was being aborted" Anyone know why? Thanks Tor
9
3265
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my problem occurs when i try to show a progress bar. The screen freezes. I know i'm not the first one to ask about it. but i'm looking
2
22967
by: Daniel Knöpfel | last post by:
Hi I am develloping an asp.net 2.0 application. For some tasks (daily notifications to users via email), we use background threads. I rather have this task as background thread of the asp.net application and not as a service as as the installation procedure of a service on the productive system would cause a lot of administrative overhead. The thread is started in the global.asax file on startup. Strangely, after some time, the thread...
1
1185
by: malu | last post by:
Hi I faced one exception when use the thread in c#. I start the thread in a class.Then i start the thread thru the main method constructor.In that thred i use the thred.sleep() method. Then one button i place in my project.That purpose is stop all functions ans close my application.In that button i call the Dispose() method.In that Dispose(0 method i call the thread.abort method.
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.