Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

Multithreaded MFC Application with Measurement Studio CNIGraph Class Hangs in MouseUp Event

Primary Software: Measurement Studio>>Visual C++ Support
Primary Software Version: 8.0
Primary Software Fixed Version: 8.0
Secondary Software: N/A

Problem: I am using the Measurement Studio CNiGraph control in MFC Visual C++ in Visual Studio .NET 2003 or Visual Studio 2005 . The application uses worker threads to plot data to the graph. I have initialized COM on the worker thread through CoInitialize or CNiComInitialize. The worker thread plots data in a while loop and allows the thread to sleep through a call to Sleep(0). The example is set up to recieve mouse up events from the graph, where I modify certain graph properties. This event is handled in the main UI thread. The application works fine as the worker thread is plotting data, but if I click on the graph and execute the code in the MouseUp event, the application hangs. What is happening and how do I fix this?

Solution: This is a known issue with the CNiGraph. To work around this you can use a mutex to prevent both threads from accessing the control at the same time. The main thread must time out and pump messages when it is unable to obtain the lock. The attached example demonstrates this workaround. The code for the workaround is enclosed in the comments /*Workaround*/.

Related Links:

Attachments:


CNiGraphThreadWorkaround.zip


Report Date: 11/07/2006
Last Updated: 04/10/2007
Document ID: 42OEDA00

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit