1D barcodes will crash ASP.NET after a short while
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.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
barcodes.Width = 200
barcodes.Height = 75
Dim image As System.Drawing.Image = barcodes.Encode(fmt, strData)
Dim ms As New IO.MemoryStream()
RE: 1D barcodes will crash ASP.NET after a short while - Added by admin 5 months ago
Any update on this? Do you observe any exception in event viewer?
RE: 1D barcodes will crash ASP.NET after a short while - Added by ChrisSchaller about 1 month 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.