private void DoFlash(IPresentationImage image, SynchronizationContext syncContext, string message)
        {
            if (!(image is IOverlayGraphicsProvider))
            {
                return;
            }

            GraphicCollection overlayGraphics = ((IOverlayGraphicsProvider)image).OverlayGraphics;

            // Prevent multiple flash graphics per image.
            var existing = overlayGraphics.OfType <FlashOverlayGraphic>().FirstOrDefault(g => g.Controller == this);

            if (existing != null)
            {
                return;
            }

            // Very little utility in flashing if nobody's looking at it.
            if (syncContext == null)
            {
                return;
            }

            var flashOverlayGraphic = new FlashOverlayGraphic(this, message);

            overlayGraphics.Add(flashOverlayGraphic);
            image.Draw();

            ThreadPool.QueueUserWorkItem(
                delegate
            {
                Thread.Sleep(FlashSpeed);
                syncContext.Post(delegate
                {
                    if (flashOverlayGraphic.IsDisposed)
                    {
                        return;
                    }

                    overlayGraphics.Remove(flashOverlayGraphic);
                    image.Draw();
                }, null);
            }, null);
        }
Beispiel #2
0
        private void DoFlash(IPresentationImage image, SynchronizationContext syncContext)
        {
            if (!(image is IOverlayGraphicsProvider))
                return;

            GraphicCollection overlayGraphics = ((IOverlayGraphicsProvider) image).OverlayGraphics;
            //Prevent multiple flash graphics per image.
            var existing = overlayGraphics.OfType<FlashOverlayGraphic>().Where(g => g.Controller == this).FirstOrDefault();
            if (existing != null)
                return;

            //Very little utility in flashing if nobody's looking at it.
            if (syncContext == null)
                return;

            var flashOverlayGraphic = new FlashOverlayGraphic(this);
            overlayGraphics.Add(flashOverlayGraphic);
            image.Draw();

            ThreadPool.QueueUserWorkItem(
                delegate
                    {
                        Thread.Sleep(FlashSpeed);
                        syncContext.Post(delegate
                                             {
                                                 if (flashOverlayGraphic.IsDisposed)
                                                     return;

                                                 overlayGraphics.Remove(flashOverlayGraphic);
                                                 image.Draw();
                                             }, null);
                    }, null);
        }