|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Crainiate.ERM.Shape multi-threadingUI thread (UT) creates Crainiate.ERM.Shape with annotation that is an int. A background thread (BT) changes the int and redraws the shape. How should the BT, instead, notify the UT to redraw the shape? Code snippet follows at the end (example project in attachment). Currently a timer (serving as BT) calls OnTimer() -> Invalidate() -> OnShapeInvalidated() I would like the timer to call OnTimer() -> Invalidate() - - > send message into UT queue and UT receives message - - > and calls OnShapeInvalidated() Thanks, Ivan public class Shape1 : Crainiate.ERM.Shape { private int i; public Shape1(Font font) { Crainiate.ERM.Annotation objAnnotation = Annotations.Add("i", font); objAnnotation.Text = i.ToString(); objAnnotation.TextRectangle = new RectangleF(20, 30, 30, 15); ShapeInvalid += new Crainiate.ERM.Shape.ShapeInvalidEventHandler(OnShapeInvalidated); } public void OnShapeInvalidated( object sender, Rectangle Rect ) { Crainiate.ERM.Annotation annotation = Annotations["i"]; annotation.Text = i.ToString(); } public void OnTimer(object obj) { i++; Invalidate(); } } You should use one of the controls Invoke() methods to force the method invocation to happen on the UI thread. But before doing that from your method you can check if you are on a different thread by using the Control.InvokeRequired property, if this property returns TRUE then you should use the Invoke() method, else you are already running on the UI thread and you can directly do your work without using Invoke().
HTH, Metallikanz! Show quote "Ivan" <ivan.rac***@dynamic-imaging.com> wrote in message news:e2$F7l49FHA.1368@TK2MSFTNGP10.phx.gbl... > if not appropriate newsgroup, let me know the appropriate one to send this to. > > > UI thread (UT) creates Crainiate.ERM.Shape with annotation that is an int. > A background thread (BT) changes the int and redraws the shape. > How should the BT, instead, notify the UT to redraw the shape? > > Code snippet follows at the end (example project in attachment). > Currently a timer (serving as BT) calls OnTimer() -> Invalidate() -> OnShapeInvalidated() > I would like the timer to call OnTimer() -> Invalidate() - - > send message into UT queue > and UT receives message - - > and calls OnShapeInvalidated() > > Thanks, > Ivan > > public class Shape1 : Crainiate.ERM.Shape > { > private int i; > > public Shape1(Font font) > { > Crainiate.ERM.Annotation objAnnotation = Annotations.Add("i", font); > objAnnotation.Text = i.ToString(); > objAnnotation.TextRectangle = new RectangleF(20, 30, 30, 15); > > ShapeInvalid += new Crainiate.ERM.Shape.ShapeInvalidEventHandler(OnShapeInvalidated); > } > > public void OnShapeInvalidated( object sender, Rectangle Rect ) > { > Crainiate.ERM.Annotation annotation = Annotations["i"]; > annotation.Text = i.ToString(); > } > > public void OnTimer(object obj) > { > i++; > Invalidate(); > } > } > > |
|||||||||||||||||||||||