Hi! I’m trying to add realtime mountain chart into WinForms project via ElementHost.
It works fine, but when I increase the chart form size and move mouse over it, it starts to block another timers events I use to update controls. It happens no matter how much datapoints I have and no matter witch render I use (HighSpeed or D3D).
Both DispatcherTimer and Forms.Timer are affected.
I’ve uploaded simple project to demonstrate this behevior:
https://drive.google.com/open?id=0B6kEDZ8g68YzcXdyRHVhSGctN0U
It simply switches between two datasets by the timer in WPF Control, and another timer updates the winforms label.
When I start to move mouse over the chart, label stops updating. If I increase the dataset update timer interval to 50-70ms it gets better, but this affects chart FPS.
Can you suggest a workaround for this behavior?
Thanks, Dennis.
UPD: I have found that without <s:SciChartSurface.ChartModifier> timers are fine.
But even an empty ChartModifier group starts to affect it.
- DENIS K asked 7 years ago
- last edited 7 years ago
- You must login to post comments
Hi Denis,
Sorry it’s taken so long to investigate this. I have just downloaded and ran the code here. I am able to reproduce the WinForms Label freezing when you mouse-over the chart quickly.
I can only guess that what’s happening is a combination of thread starvation and WPF/WinForms message pump interaction issues.
Basically, if your UI thread is super busy, then WPF and Winforms start fighting about who gets CPU time. That means a mouse event processed by WPF can steal a timer event in WinForms.
Some observations:
-
) I tried use of SciChartSurface.RenderPriority = Low . No change
2.) I tried use of Application.DoEvents in your System.Windows.Forms.Timer Tick lander. No change
3.) I added this code to your tick hander:public void TimerOnElapsed(object sender, EventArgs e) { //this.Invoke((MethodInvoker)delegate { label1.Text = string.Format("{0}", count); Console.WriteLine("Label was updated + " + count++); //}); }
3.a) When System.Windows.Forms.Timer is used, the Console line is not written when mouse moves fast.
3.b) When DispatcherTimer is used, the console line is written but WinForms label is not updated.
I actually have no idea how to solve this. I will google around a bit. What I can say is that its clear WPF message pump seems to be operating at a higher priority than WinForms so is stealing the focus from WinForms. You also can’t force it with DoEvents.
- Andrew Burnett-Thompson answered 7 years ago
- You must login to post comments
Bit more info here.
Seems to be an issue common to WPF/WinForms interop, not just SciChart related.
1.) WPF block the timer event in WinForm application
2.) ElementHost blocks mouse events
I’m afraid I don’t have any solution for you, other than to say that areas of the UI which are performance critical and should be updated in realtime may have to be WPF, no WinForms.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 7 years ago
- You must login to post comments
Update / SciChart WPF v6
We have another possible solution to this problem.
Sometimes the message loops in WPF and Windows Forms can conflict, especially if the application is under high load.
If setting SciChartSurface.RenderPriority = RenderPriority.Low does not work then you can try setting RenderSurfaceBase.UseThreadedRenderTimer = true.
This provides an alternative timer for drawing which has better compatibility / performance with Windows forms.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 3 years ago
- You must login to post comments
Please login first to submit.