ThreadAbortException Question

B

Burak Gunay

Hello,

I have a piece of code where I am writing the contents of a datagrid to
an excel report

Dim tw As New StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition",
"attachment;filename=Test.xls")
Response.Charset = ""
EnableViewState = False
Controls.Add(frm)
frm.Controls.Add(grid2)
frm.RenderControl(hw)

Response.Write(tw.ToString())
Response.End()

it works fine.

In debug mode, after I closed down the excel report and exited the
program, I saw the following message in the debug window

"A first chance exception of type
'System.Threading.ThreadAbortException' occurred in mscorlib.dll
An exception of type 'System.Threading.ThreadAbortException' occurred
in mscorlib.dll but was not handled in user code
The program '[1368] WebDev.WebServer.EXE: Managed' has exited with code
0 (0x0)."

I looked at msdn

http://msdn.microsoft.com/library/?...emthreadingthreadabortexceptionclasstopic.asp


and put a try-catch block around the code to ctach ThreadAbortException
but this time it came back with a "page can not have 2 forms error".

The program works fine. Is this a serious issue? Do I need to catch
this exception? It seems like catching it actually mad ethings worse.

Thanks,

Burak
 
K

Karl Seguin [MVP]

Response.End() intentionally throws a ThreadAbortException - it's actually
how it works.

Karl
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top