Canvas.Graphics & Threads

Hi all,

I know that the update of the graphics object of a canvas should take place only from the Paint event. I have two issues here:

I am on Windows

A.

  1. Create a subclass of the Canvas
  2. Add a method, eg. myRefresh
  3. in myRefresh write:

dim p as new picture(me.width, me.height) self.graphics.drawpicture p,0,0

  1. Analyse the project (Ctrl-K)

The first time you get a warning about the deprecated item. If you analyse the project again, the compiler doesn’t complain.

So, what does this mean? That it doesn’t show the message again or the second time it doesn’t find any issues?

B. I am aware of the structure: GUI element (eg. canvas) - Timer - Thread

Now, all the examples I have come across put the timer and the thread outside the canvas (in the window class).

What about if I subclass Canvas and add a thread and a timer that calls the refresh? Most likely the timer isn’t a problem but is the thread safe?

Thanks for your help

John

It doesn’t show the message again, which is probably a bug of some kind. Seems like it should be consistent.

No, that wouldn’t make it thread safe. And you really can’t do that anyway, at least not in the way you think of doing it in a window. All you can do in a canvas subclass is to have properties of type Timer and Thread. The objects themselves don’t “belong” to the canvas in any meaningful way, it simply has a reference to them.