示例#1
1
 public void PostDelayed(AMCMsg.Runner runnable, long delay)
 {
     AMCMsg msg = new AMCMsg();
     msg.targetTime = Util.DelayMs(delay);
     msg.SetTarget(this);
     msg.Runnable = runnable;
     SendAtTime(msg, msg.targetTime);
 }
示例#2
0
 public void Post(AMCMsg.Runner runnable)
 {
     AMCMsg msg = new AMCMsg();
     msg.SetTarget(this);
     msg.Runnable = runnable;
     msg.targetTime = Util.NowMs;
     Send(msg);
 }
示例#3
0
 public override void HandleMessage(AMCMsg msg)
 {
     Debug.WriteLine("Handler1 to process message " + msg.what + " at ticket " +
         Util.GetMilliseconds(DateTime.Now.Ticks));
     switch (msg.what)
     {
         case 1:
             break;
         case 2:
             break;
         case 3:
             Debug.WriteLine("3:" + msg.obj);
             break;
         case 4:
             Debug.WriteLine("4:" + msg.GetData().get<String>("key", null));
             break;
         default:
             Debug.WriteLine("Unknown message " + msg.what);
             break;
     }
 }
示例#4
0
 internal void Add(AMCMsg message)
 {
     if (message.used)
     {
         throw new InvalidOperationException("one AMCMsg can not be add to queue multiple times");
     }
     lock(_messages){
         message.used = true;
         _messages.Add(message);
         Monitor.PulseAll(_messages);
     }
 }
示例#5
0
 public void SendAtTime(AMCMsg message, long time)
 {
     message.targetTime = time;
     message.SetTarget(this);
     _looper.Add(message);
 }
示例#6
0
 public void Send(AMCMsg message, long delay)
 {
     SendAtTime(message, Util.DelayMs(delay));
 }
示例#7
0
 public void Send(AMCMsg message)
 {
     SendAtTime(message, Util.NowMs);
 }
示例#8
0
 public virtual void HandleMessage(AMCMsg message)
 {
 }
示例#9
0
 public void WaitProcess(AMCMsg message)
 {
     message.waiter = new Object();
     SendAtTime(message, Util.NowMs);
     lock (message.waiter)
     {
         Monitor.Wait(message.waiter);
     }
 }
示例#10
0
 public void WaitProcess(string what)
 {
     AMCMsg message = new AMCMsg(what);
     message.waiter = new Object();
     SendAtTime(message, Util.NowMs);
     lock (message.waiter)
     {
         Monitor.Wait(message.waiter);
     }
 }