我在 C# 中有代码,其中 Window 正在获取消息(来自 GigE 相机的图像)。在函数处理程序中,我调用另一个函数对从消息中获得的图像进行一些处理。此处理可能需要比我收到下一条消息之间的时间更多的时间。我想使用一些不错的机制来忽略消息,直到处理完成。我可以简单地写:
bool is_processing = false;
void HandleUeyeMessage(int wParam, int lParam)
{
frame = getNewFrame();
if(!is_processing) {
doProcessing(frame);
} else non-blocking ignore
}
void doProcessing(frame f)
{
is_processing = true;
// some processing work...
is_processing = false;
return;
}
但我想使用一些同步机制,但我真的不知道该使用什么,因为这通常不是线程的东西......