Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Waveform graph blanks when another window moves in front

I am using a Waveform Graph in a managed C++ application in Visual Studio .NET 2003. If another window moves in front of the control (for example, a Open File dialog box), and then the window goes away, the control will blank (become solid of form color) where the window was overlapping the control. It also happens when the control is brought behind another control, and then brought back. The refresh method does not seem to force it to redraw. What will? Thanks.
0 Kudos
Message 1 of 4
(3,414 Views)
I am not able to reproduce the problem that you're describing. Could you please post a small test project that demonstrates this behavior? Thanks.

- Elton
0 Kudos
Message 2 of 4
(3,410 Views)
I believe I discovered what was causing it while I was creating an example file to send.

The code that adds data to the control is run in its own thread. Before adding data, I call

waveformGraph1->BeginUpdate();
waveformGraph1->ClearData();

then go through and add my data with PlotYAppend, and then call

waveformGraph1->EndUpdate();

once all the data is in, and the thread loops until it is killed.

It seems that if the thread gets killed after BeginUpdate() but before EndUpdate(), the symptoms I described earlier occur, which seems to make sense as BeginUpdate() suspends painting the control.

I just added code to call EndUpdate() after the thread is killed, and this solves the blanking problem. However, now it draws the incomplete graph that the thread was in the process of drawing. Is there any method like AbortUpdate that would start the control painting, but not draw whats in the not-yet-full buffer? Thanks.
0 Kudos
Message 3 of 4
(3,403 Views)
Unfortunately, there is not anything like an AbortUpdate. The best way to handle this would be to set up a try/catch/finally block and add code to the catch block to put the graph back into a default state if an exception is thrown. I also suggest putting the call to EndUpdate in the finally block so that EndUpdate is guaranteed to be called, even if an exception is thrown.

Also, you could potentially run into problems with the way that you're updating the graph from another thread because Windows Forms controls are not thread-safe. Notice that the class overviews of all .NET Framework and Measurement Studio Windows Forms controls have a thread safety section that states:

"Only the following members are safe for multithreaded operations: BeginInvoke, EndInvoke, Invoke, InvokeRequired, and CreateGraphics."

For more information about accessing Windows Forms controls from non-UI threads, see the .NET Quickstart article "Making procedure calls across thread boundaries".

- Elton
0 Kudos
Message 4 of 4
(3,397 Views)