[英]ManualResetEvent.WaitOne() causes AccessViolation
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. ASP.NET发票应用程序具有一个保存按钮,该按钮(除其他外)触发使用表单数据,用户ID等在磁盘上生成pdf文件。
An excerpt from the GeneratePDF
method: 摘自GeneratePDF
方法:
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. 出于某种原因, WaitOne()
方法在大多数情况下会抛出AccessViolation
,但并非总是如此 ,但是我似乎无法进一步调试。 Beyond that is mscorlib
. 除此之外,还有mscorlib
。
Three things are important to understand in this story: 在这个故事中要理解三件事很重要:
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. 由于我对线程的理解受到严格限制,因此我将根据您的要求更新问题。
Apparently (and don't shoot me here, I realize this is horrible, HORRIBLE coding because it resolves nothing except not take the process down) I can make the problem go away by enclosing the aforementioned code block in a try-catch
. 显然(并且不要在这里开枪,我意识到这是可怕的,可怕的编码,因为它除了解决过程之外没有解决任何问题),可以通过将上述代码块放在try-catch
。
Sadly, this doesn't reveal any inkling about what might be causing the AccessViolation
. 可悲的是,这并没有揭示任何可能导致AccessViolation
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.