• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 16. Graphics Fundamentals > Graphics and Threads

16.5. Graphics and Threads

Typically, application code invokes graphical operations from the user interface thread, as was described in the section Apartment Threading. However, unlike the API provided by the widget classes, this is not a requirement for the drawing operations in class GC (although the GC must be created and disposed of in the user interface thread). Despite this, there are at least three good reasons to use the user interface thread for drawing.

  1. It is predictable. It is easier to implement code that does all drawing from the UI thread, because the relationship between when the graphics are drawn and when widget operations occur is predictable. For example, any code that performs a sequence of drawing operations in a background thread must be prepared to handle the fact that controls may be disposed of in the UI thread at any time. Contrast this to code that draws only from the user interface thread, which can be assured that once it begins running, no widget will be disposed of (unless the code itself does it) until after the code has completed.

  2. It is easier to manage. Because all user interface operations from non-user-interface threads would be wrapped with asyncExec() or syncExec(), graphical operations can be easily mixed with widget operations.

  3. It is bounded. On some operating systems, if many background drawing operations are performed without pauses between them, the platform cannot deal with them fast enough. In extreme cases, this can cause your application to freeze, crash, or even cause the operating system itself to behave unpredictably.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint