简体   繁体   English

ManualResetEvent.WaitOne()导致AccessViolation

[英]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: 在这个故事中要理解三件事很重要:

  • 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. 由于我对线程的理解受到严格限制,因此我将根据您的要求更新问题。

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.

相关问题 ManualResetEvent.WaitOne卡住了GUI - ManualResetEvent.WaitOne stuck the GUI ManualResetEvent.WaitOne()返回false而不超时? - ManualResetEvent.WaitOne() returning false without timeout? 如何继续前进之前等待ManualResetEvent.WaitOne()到达? - How to wait for ManualResetEvent.WaitOne() to be reached before moving on? ManualResetEvent.WaitOne始终挂在ASP.NET MVC中 - ManualResetEvent.WaitOne is always hanging in ASP.NET MVC ManualResetEvent.WaitOne()抛出NullReferenceException:对象引用未设置为对象的实例 - ManualResetEvent.WaitOne() throws NullReferenceException: Object reference not set to an instance of an object 如何为包含ManualResetEvent.WaitOne()的异步(套接字)代码编写单元测试? - How to write unit test for asynchronous (socket) code that includes ManualResetEvent.WaitOne()? 如果在Set()之后立即调用Reset(),则ManualResetEvent.WaitOne()不会返回 - ManualResetEvent.WaitOne() doesn't return if Reset() is called immediately after Set() C# - 阻塞主线程直到从线程执行 ManualResetEvent.WaitOne() - C# - Block master-thread until slave-thread executed ManualResetEvent.WaitOne() WaitOne()不会在ManualResetEvent中等待 - WaitOne() doesnot wait in ManualResetEvent ManualResetEvent WaitOne没有解锁 - ManualResetEvent WaitOne not unblocking
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM