开发者

OnRender(DrawingContext drawingContext) C#

I'm overriding OnRender(DrawingContext drawingContext) in an Adorner class in C#

In this Method I'm trying to draw images stored in my imageCache Dictionary. The problem is OnRender Method gets called before the Thread that stores my images in the dictionary finishes.

I tried to Thread.Sleep(60) this works but my program g开发者_如何学Pythonot really slow.

Can you guys give me ideas how I can overpass this issue.

Thank you.


Does you thread which stores images in a dictionary run once? If so, I suggest you to do nothing in your OnRender until your image-storing thread finishes.

But if your image-storing thread runs for every render or frequently, you might need to implement some thread syncronization (well you'll need it for the fist case too). For example, you can have reference to a dictionary with old images for rendering purposes, then after your worker thread built a new dictionary, you can use lock and assign a new dictionary to that reference.

(That's all I can suggest with so little input)


You can lock and synchronize the threads by using Mutex.

private static Mutex mut = new Mutex();

and then you can lock and release the methods you want by using

mut.WaitOne();
mut.ReleaseMutex();

and here is the MSDN tutorial.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜