I have code in C# where Window is getting messages (images from GigE camera). In function handler I call another function to do some processing on the image I get from message. This processing can take more time than time between next message I get. I would like to use some nice mechanism to ignore messages until processing will be done. I could simply write:
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;
}
but I want to use some synchronization mechanism, but I don't really know what to use because this is not generally threading thing...
you cannot ignore messages in a single thread- they will be queued and processed when your app is able to respond. You can use worker thread with some basic synchronization.
BackgroundWorker _worker=new BackgroundWorker();
void OnMessage(int lparam, int wparam)
{
frame frame=GetFrame();
if(!_worker.IsBusy)
_worker.RunWorkerAsync(frame);
}
void DoWork(object sender,DoWorkEventArgs e)
{
//do processing
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.