C# 单线程程序的事件订阅限制
我正在尝试监视在单线程程序中并行运行的许多 HPC 作业的状态,我正在订阅 OnJobState 引发的事件,并且当监视少至三个作业时,事件状态更改将丢失并且作业卡在运行状态。
我假设每个作业需要一个线程来捕获所有事件,但我找不到有关单线程程序中事件订阅限制的任何信息。
我本以为 .net 平台会将所有这些都排队,但事实似乎并非如此。
I'm attempting to monitor the status of many HPC jobs running in parallel in a single threaded program, I'm subscribing to events raised by OnJobState and when monitoring as few as three jobs event state changes will go missing and the job is stuck running.
I'm assuming I need a thread per job to catch all the events but I can't find any information about the limits of events subscripton in a single thread program.
I would have thought the .net platform would queue this all up but that doesn't appear to be the case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,事件是同步的。这意味着引发事件的对象只有在所有事件处理程序完成其工作后才会继续执行。事件处理程序将在与引发事件的对象相同的线程上运行。这导致了以下结论:
Events are synchronous by default. That means that the object that raises an event will continue its execution only after all event handlers finished their work. The event handlers will run on the same thread as the object that raises the event. That leads to the following conclusions:
我使这个问题更加笼统,以消除对 HPC 的困惑,看起来就像我无法控制事件处理程序的执行方式一样,所以我需要使其线程安全。
I made this question more general to remove the confusion over HPC, looks like I have no control over how my event hander is executed so I need to make it thread safe.