Project

General

Profile

1D barcodes will crash ASP.NET after a short while

Added by hunter over 6 years ago

Hi, great component.

Firstly, some API documentation would be good. Most is straight forward, but things like .MarginSize need explaining (as any value 1,2,3,100) seem to not change the margin.

If I use QRCode or DataMatrix, it works very well.

Using Code39 or Code11, after about 10 draws, my application becomes very unstable, corrupting the database connection and crashing the w3wp ASP.NET web service. On one system (IIS7.1) I can terminate that service and it all works for a short time longer before crashing again. On another server (IIS6) i have to reboot Windows. Memory usage and CPU seem stable.

I am trying to get more information for you. Will let you know if i discover anything more. Here is my code. This runs in an .ashx file.

Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
context.Response.Clear()
context.Response.ClearContent()
context.Response.ClearHeaders()
context.Response.Cache.SetCacheability(HttpCacheability.Public)
context.Response.BufferOutput = False
context.Response.ContentType = "image/png"
context.Response.AppendHeader("Content-Disposition", " filename=""barcode-" & Guid.NewGuid().ToString() & ".png""")
Dim strFormat As String = HttpContext.Current.Request.QueryString("format")
Dim strData As String = HttpContext.Current.Request.QueryString("data")
Dim fmt As BarcodeFormat = [Enum].Parse(GetType(BarcodeFormat), strFormat)
Dim barcodes As New BarcodeEncoder()
'barcodes.MarginSize = 5
If strFormat = "QRCode" Then
barcodes.Width = 100
barcodes.Height = 100
Else
barcodes.Width = 200
barcodes.Height = 75
End If
Dim image As System.Drawing.Image = barcodes.Encode(fmt, strData)
Dim ms As New IO.MemoryStream()
barcodes.SaveImage(ms, SaveOptions.Png)
context.Response.BinaryWrite(ms.GetBuffer())
context.Response.Flush()
context.Response.Close()
context.Response.End()
ms.Dispose()
image.Dispose()
barcodes.Dispose()
End Sub

Replies (2)

RE: 1D barcodes will crash ASP.NET after a short while - Added by admin about 6 years ago

Hi,

Any update on this? Do you observe any exception in event viewer?

Thanks
Regards
admin

RE: 1D barcodes will crash ASP.NET after a short while - Added by ChrisSchaller almost 6 years ago

I am running a similar handler, without any issues.
I'm writing in C# and by implementing 'using' blocks, all disposable instances are cleared up regarless of how or when the response is ended.
I've noticed in my solution that any code after context.Response.End() does not execute, exceptions are logged off thread. Effectively the thread is aborted.
So in your code above, I would move the dispose calls to before response.end. More importantly through you should use a try/finally pattern or using pattern to ensure that resources are indeed cleaned up correctly.

    (1-2/2)