c# - Is it possible to create a GUI control that can be accessed from two Threads? -
in order create little 2d game scratch, i'd create panel on winform , draw using graphics-object (btw, have use panel or draw form directly? know can this, disadvantages?).
now want continously run 2 loops in different threads. 1 thread should primary assigned calculations , other 1 should primary draw panel. in cases however, both threads should able draw panel , problem occurs. know, error occurs if try access gui control not created specific thread. don't want use code
if (control1.invokerequired) { control1.invoke(new methodinvoker(delegate { control1.text = string1; })); }
because i'm not familiar option. there way create panel in way both threads can access or impossible?
is there way create panel in way both threads can access or impossible?
no. don't want that. there lot of history behind why in windows, short answer is, gui thread should doing of drawing , accessing of controls.
btw, have use panel or draw form directly? know can this, disadvantages?
winforms in general not best option high-performance drawing - of it's drawing cpu instead of gpu. can use wpf hardware assisted drawing, usual approach go down directx approach , using directdraw or direct2d. depending on expectations , needs are, winforms may work fine.
to answer actual question, there isn't of difference between drawing directly on form vs. panel.
because i'm not familiar option.
i codecaster's comment on this. spend bit of time on , shouldn't difficult hang of. "gui thread" (main thread, whatever want call it) operates on message pump. think of queue different priorities. gui thread spends time in message loop handling items in queue. "set control's text that", "draw here", "repaint because window resized", etc. control.invoke
boils down adding item on queue gui thread do.
Comments
Post a Comment