Пример #1
0
        /// <summary>
        /// Adds the given message to the map's message queue and does not return
        /// until the message is processed.
        /// </summary>
        /// <remarks>Make sure that the map is running before calling this method.</remarks>
        /// <remarks>Must not be called from the map context.</remarks>
        public void AddMessageAndWait(bool allowInstantExecution, IMessage msg)
        {
            if (allowInstantExecution && IsInContext)
            {
                msg.Execute();
            }
            else
            {
                EnsureNoContext();

                // to ensure that we are not exiting in the current message-loop, add an updatable
                // which again registers the message
                var updatable = new SimpleUpdatable();
                updatable.Callback = () => AddMessage(new Message(() =>
                {
                    msg.Execute();
                    lock (msg)
                    {
                        Monitor.PulseAll(msg);
                    }
                    UnregisterUpdatable(updatable);
                }));

                lock (msg)
                {
                    RegisterUpdatableLater(updatable);
                    // int delay = this.GetWaitDelay();
                    Monitor.Wait(msg);
                    // Assert.IsTrue(added, string.Format(debugMsg, args));
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Adds the given message to the map's message queue and does not return
 /// until the message is processed.
 /// </summary>
 /// <remarks>Make sure that the map is running before calling this method.</remarks>
 /// <remarks>Must not be called from the map context.</remarks>
 public void AddMessageAndWait(bool allowInstantExecution, IMessage msg)
 {
     if (allowInstantExecution && IsInContext)
     {
         msg.Execute();
     }
     else
     {
         EnsureNoContext();
         SimpleUpdatable updatable = new SimpleUpdatable();
         updatable.Callback = () => AddMessage(new Message(() =>
         {
             msg.Execute();
             lock (msg)
                 Monitor.PulseAll(msg);
             UnregisterUpdatable(updatable);
         }));
         lock (msg)
         {
             RegisterUpdatableLater(updatable);
             Monitor.Wait(msg);
         }
     }
 }
Пример #3
0
 /// <summary>
 /// Adds the given message to the map's message queue and does not return
 /// until the message is processed.
 /// </summary>
 /// <remarks>Make sure that the map is running before calling this method.</remarks>
 /// <remarks>Must not be called from the map context.</remarks>
 public void AddMessageAndWait(bool allowInstantExecution, IMessage msg)
 {
     if (allowInstantExecution && this.IsInContext)
     {
         msg.Execute();
     }
     else
     {
         this.EnsureNoContext();
         SimpleUpdatable updatable = new SimpleUpdatable();
         updatable.Callback = (Action)(() => this.AddMessage((IMessage) new Message((Action)(() =>
         {
             msg.Execute();
             lock (msg)
                 Monitor.PulseAll((object)msg);
             this.UnregisterUpdatable((IUpdatable)updatable);
         }))));
         lock (msg)
         {
             this.RegisterUpdatableLater((IUpdatable)updatable);
             Monitor.Wait((object)msg);
         }
     }
 }