CreateGraphics

  • Thread starter Thread starter Jon Shemitz
  • Start date Start date
J

Jon Shemitz

It's safe to "call [CreateGraphics] from any thread" - does that mean
it's also safe to use that Graphics object from the thread it was
created in, and draw on a control from a thread that didn't create the
control?
 
I would say yes, since a Graphics object is not a Control
Hence you're not calling any methods or properties on
a Control

/claes
 
Jon Shemitz said:
It's safe to "call [CreateGraphics] from any thread"
ACK.

- does that mean it's also safe to use that Graphics object
from the thread it was created in, and draw on a control
from a thread that didn't create the control?

Yes.
 
Herfried K. Wagner said:
Jon Shemitz said:
It's safe to "call [CreateGraphics] from any thread"
ACK.

- does that mean it's also safe to use that Graphics object
from the thread it was created in, and draw on a control
from a thread that didn't create the control?

Yes.

Is it really safe to use a Graphics object from another thread? How do you
know that Windows is not using the same device context to do its own
painting while you are using it from another thread? Is this documented
somewhere?

Thanks,
Sami
 
Sami Vaaraniemi said:
Jon Shemitz said:
It's safe to "call [CreateGraphics] from any thread"
ACK.

- does that mean it's also safe to use that Graphics object
from the thread it was created in, and draw on a control
from a thread that didn't create the control?

Yes.

I read your question too quickly. No, it's not thread-safe to call instance
methods of the /'Graphics'/ object from another thread than it was created
on, but I assume it's allowed to call the methods from the thread in which
the 'Graphics' object was created.
 
Hi,

Yes, you can call Create graphics in any thread but returned object cannot
be share between threads, Traying to use shared graphics object will most
likely throw exception that the graphics object is in use by another thread.

--

Stoitcho Goutsev (100) [C# MVP]


Herfried K. Wagner said:
Sami Vaaraniemi said:
It's safe to "call [CreateGraphics] from any thread"

ACK.

- does that mean it's also safe to use that Graphics object
from the thread it was created in, and draw on a control
from a thread that didn't create the control?

Yes.

I read your question too quickly. No, it's not thread-safe to call
instance methods of the /'Graphics'/ object from another thread than it
was created on, but I assume it's allowed to call the methods from the
thread in which the 'Graphics' object was created.
 
Back
Top