LiveCharts2
LiveCharts2 copied to clipboard
When is it safe to add geometry to charts?
I am adding graphics objects by calling AddGeometryToPaintTask. This works fine except when my application is creating a Chart object for the first time. The flow is:
- Application started but window containing chart is not created as it is not yet needed
- User opens a project file
- The project specifies a chart window so the window is created
- The project specifies some graphics objects for the chart so AddGeometryToPaintTask is called
What I find is that this seems to cause data corruption somewhere. I get exceptions about indexoutofrange but this is coming from inside the LiveCharts2 or native code and the call stack just shows windows calls. I get strange things like creating a LvcPoint(200, 0) shows the LvcPoint.X value is some random very small value on the next line after the LvcPoint constructor call.
The workaround is to wait a certain amount of time after the project has finished loading before I start calling AddGeometryToPaintTask. For example if I wait 1000ms then everything works fine.
However a delay of 1000ms might work on my PC but a slower PC might need more time. So here is the question:
Is there a point in the LiveCharts2 initialization code, or an event, when it is safe to start adding geometry? If there isn't an event I can add one to my copy of the code, but I need to know where to add it.
I tried doing it in the first call to the Measuring event but that still gave the weird errors. I also tried the VisibleChanged event and that was the same.
Note that the calls to AddGeometryToPaintTask themselves don't raise an exception, it is some random line later on in the code. or the exception is simply reported for Application.Run().
Using WinForms.
Thanks, Andy