An ASP.NET invoice application has a save button, that triggers (among other things) the generation of a pdf file on disk using the form data, the userID etc.
An excerpt from the GeneratePDF
method:
ManualResetEvent generateInvoiceEvent;
generateInvoiceEvent = new ManualResetEvent(false);
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
ThreadPool.QueueUserWorkItem(delegate
{
Thread.CurrentThread.CurrentCulture = currentCulture;
Thread.CurrentThread.CurrentUICulture = currentCulture;
InvoicePdfGenerator generator = new InvoicePdfGenerator();
generator.SetTranslationFile(GetFileSharedFilePath());
generator.DrawPdf(invoiceXml, pdfFilePath, invoiceLanguage.ValueCode,
currentCulture, invoiceLayoutXml, imageRootFolder);
generateInvoiceEvent.Set(); //Signal completion of invoice generation
}
);
generateInvoiceEvent.WaitOne();
For some reason, the WaitOne()
method throws an AccessViolation
most of the time but not always, but I don't seem to able to debug further than that. Beyond that is mscorlib
.
Three things are important to understand in this story:
- This is not my code
- I have little knowledge about threading. It's just something I rarely come into contact with in my job.
- This worked fine up until a few weeks ago on my development machine. Chances are, that some external factor is causing this, but I cannot find what or why. There are no code updates between then and now.
It's quite possible, that this question needs additional info. As my understanding of threading is severely limited, I will update my question at your request.