c# - Multithreaded drawing in .NET? -
(edit: clarify, main goal concurrency, not multi-core machines)
i'm new concepts on concurrency, figured out needed have parallel drawing routines, number of reasons:
- i wanted draw different portions of graphic separatedly (background refreshed less foreground, kept on buffer).
- i wanted control priority (more priority ui responsiveness drawing complex graph).
- i wanted have per-frame drawing calculations multithreaded.
- i wanted offer cancelling complex on-buffer drawing routines.
however, being such beginner, code looked mess , refactoring or bug-fixing became awkward decided need play more before doing serious.
so, i'd know how make clean, easy mantain .net multithreaded code makes sense when @ after waking next day. bigest issue had structuring application parts talk each other in smart (as opposed awkward , hacky) way.
any suggestion welcome, have preference sources can digest in free time (e.g., not 500+ pages treatise on concurrency) , c#/vb.net, latest version (since see there have been advances). want straight point can started playing concepts on toy projects.
the task parallel library place simplifying code. i've written (semi-long) introduction parallelism .net 4 covers quite few concepts useful.
be aware, however, want consider leaving drawing single threaded. should try keep computation multithreaded, , actual drawing operations done on gui thread.
most drawing apis require actual drawing calls happen on same synchronization context.
that being said, using new collection classes concurrentqueue simplify type of code. try think in terms of lots of threads (producers) adding "drawing operations" shared, concurrent queue - , 1 thread (the consumer) grabbing operations , performing them.
this gives reasonably scalable, simple design on can build.
Comments
Post a Comment