コード例 #1
0
ファイル: ResponseThread.cs プロジェクト: pepipe/ISEL
 public TSResponse getResponse(string id)
 {
     try
     {
         Monitor.Enter(mutex);
         while (lastEvent == null || !lastEvent.Id.Equals(id))
         {
             Monitor.Exit(mutex);
             autoResetEvent.WaitOne();
             Monitor.Enter(mutex);
         }
         TSResponse r = lastEvent;
         lastEvent = null;
         return r;
     }
     finally
     {
         Monitor.Exit(mutex);
     }
 }
コード例 #2
0
ファイル: ResponseThread.cs プロジェクト: pepipe/ISEL
        public void run()
        {
            bool running = true;
            Thread.CurrentThread.Name = "ResponseThread";
            while(running)
            {
                try
                {
                    string buffer = reader.ReadLine();
                    if(!buffer.Trim().Equals(string.Empty))
                    {
                        if (buffer == null)
                        {
                            running = false;
                        }
                    }

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(buffer);
                    XmlElement root = doc.DocumentElement;
                    if(root.Name.Equals("response"))
                    {
                        lastEvent = new TSResponse(root);
                    }
                    else if (root.Name.Equals("callback"))
                    {
                        CallbackCommand cbCommand = new CallbackCommand(root);
                        Callback cback = seqToCallback[cbCommand.SequenceNumber];
                        if(callbackUseThread[cback])
                        {
                            CallConcurrentThread cct = new CallConcurrentThread(cback, cbCommand);
                            new Thread(new ThreadStart(cct.Run)).Start();
                        }
                        else
                        {
                            Call(cback, cbCommand);
                        }
                    }
            //                    Monitor.Enter(mutex);
                    autoResetEvent.Set();
            //                    Monitor.Exit(mutex);
                }
                catch (System.Exception e)
                {
                    Console.Out.WriteLine(e.StackTrace);
                    running = false;
                }
            }
        }