[英]DataVisualization.Charting.Chart PostPaint Event Firing Prematurely
I have a complex chart that I'm drawing and the PostPaint event for System.Windows.Forms.DataVisualization.Charting.Chart seems to be firing prematurely. 我有一个正在绘制的复杂图表,System.Windows.Forms.DataVisualization.Charting.Chart的PostPaint事件似乎过早触发。 There is no chart on the screen yet.
屏幕上还没有图表。
Does anyone have a better understanding of the behavior of the PostPaint event with large charts? 有人对大型图表对PostPaint事件的行为有更好的了解吗? Is there a better event to listen to?
有更好的活动要听吗? Recommended strategies?
推荐策略?
I'm not sure posting code would provide any benefit. 我不确定发布代码会带来任何好处。
ORIGINAL POST: So it turns out the answer to this (for me anyway), is to create another thread (I'm doing it with a Task) off of the event. 原始帖子:事实证明,这个问题的答案(无论如何对我来说)是在事件之外创建另一个线程(我正在使用Task进行此操作)。 This thread's job is to continually compare the region with an empty image and when it is no longer empty, grab the image and save it in the database.
该线程的工作是不断地将区域与空图像进行比较,当该区域不再为空时,抓取图像并将其保存在数据库中。 Because it's a thread, this frees up the chart to eventually render itself.
因为它是线程,所以释放了图表以最终呈现自己。
FINAL POST: In the end, I had to put a lock inside the PostPaint event (it was firing multiple times as TaW indicated it would) and make sure the code inside would only execute a single time (I have a Draw button so these controls get reset every time it's clicked). 最终发布:最后,我必须在PostPaint事件中放置一个锁(它如TaW所示将触发多次),并确保其中的代码仅执行一次(我有一个Draw按钮,因此这些控件每次点击都会重置)。 Additionally, it was necessary for me to create a task to actually do the work of capturing the image and storing it in the database.
另外,对于我来说,有必要创建一个任务来实际完成捕获图像并将其存储在数据库中的工作。 If I didn't do this, I would get a blank image every time.
如果不这样做,每次都会得到一张空白图像。 I did not actually have to check point count or sample the image to see if it was blank.
我实际上不必检查点数或对图像进行采样以查看其是否为空白。
Locking down the event and creating the task inside the event is what made the difference. 锁定事件并在事件内部创建任务是与众不同的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.