context: // **********************************************************************
  //
  // Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
  //
  // This copy of Ice is licensed to you under the terms described in the
  // ICE_LICENSE file included in this distribution.
  //
  // **********************************************************************
  
  using System;
  using System.Collections.Generic;
  using System.Threading;
  
  public sealed class MyDerivedClassI : Test.MyDerivedClassTie_
  {
      public MyDerivedClassI() : base(new MyDerivedClassTieI())
      {
      }
  }
  
  public sealed class MyDerivedClassTieI : Test.MyDerivedClassOperations_
  {
      private static void test(bool b)
      {
          if (!b)
          {
              throw new Exception();
          }
      }
  
      internal class Thread_opVoid
      {
          public Thread_opVoid(Test.AMD_MyClass_opVoid cb)
          {
              _cb = cb;
          }
  
          public void Start()
          {
              lock(this)
              {
                  _thread = new Thread(new ThreadStart(Run));
                  _thread.Start();
              }
          }
  
          public void Run()
          {
              _cb.ice_response();
          }
  
          public void Join()
          {
              lock(this)
              {
                  _thread.Join();
              }
          }
  
          private Test.AMD_MyClass_opVoid _cb;
          private Thread _thread;
      }
  
      public void shutdown_async(Test.AMD_MyClass_shutdown cb, Ice.Current current)
      {
          while(_opVoidThread != null)
          {
              _opVoidThread.Join();
              _opVoidThread = null;
          }
  
          current.adapter.getCommunicator().shutdown();
          cb.ice_response();
      }
  
      public void delay_async(Test.AMD_MyClass_delay cb, int ms, Ice.Current current)
      {
          System.Threading.Thread.Sleep(ms);
          cb.ice_response();
      }
  
      public void opVoid_async(Test.AMD_MyClass_opVoid cb, Ice.Current current)
      {
          test(current.mode == Ice.OperationMode.Normal);
  
          while(_opVoidThread != null)
          {
              _opVoidThread.Join();
              _opVoidThread = null;
          }
  
          _opVoidThread = new Thread_opVoid(cb);
          _opVoidThread.Start();
      }
  
      public void opBool_async(Test.AMD_MyClass_opBool cb, bool p1, bool p2, Ice.Current current)
      {
          cb.ice_response(p2, p1);
      }
  
      public void opBoolS_async(Test.AMD_MyClass_opBoolS cb, Test.BoolS p1, Test.BoolS p2, Ice.Current current)
      {
          Test.BoolS p3 = new Test.BoolS();
          p3.AddRange(p1);
          p3.AddRange(p2);
  
          Test.BoolS r = new Test.BoolS();
          for(int i = 0; i < p1.Count; i++)
          {
              r.Add(p1[p1.Count - (i + 1)]);
          }
          cb.ice_response(r, p3);
      }
  
      public void opBoolSS_async(Test.AMD_MyClass_opBoolSS cb, Test.BoolSS p1, Test.BoolSS p2, Ice.Current current)
      {
          Test.BoolSS p3 = new Test.BoolSS();
          p3.AddRange(p1);
          p3.AddRange(p2);
  
          Test.BoolSS r = new Test.BoolSS();
          for(int i = 0; i < p1.Count; i++)
          {
              r.Add(p1[p1.Count - (i + 1)]);
          }
          cb.ice_response(r, p3);
      }
  
      public void opByte_async(Test.AMD_MyClass_opByte cb, byte p1, byte p2, Ice.Current current)
      {
          cb.ice_response(p1, (byte)(p1 ^ p2));
      }
  
      public void opByteBoolD_async(Test.AMD_MyClass_opByteBoolD cb, Dictionary<byte, bool> p1,
                                    Dictionary<byte, bool> p2, Ice.Current current)
      {
          Dictionary<byte, bool> p3 = p1;
          Dictionary<byte, bool> r = new Dictionary<byte, bool>();
          foreach(KeyValuePair<byte, bool> e in p1)
          {
              r[e.Key] = e.Value;
          }
          foreach(KeyValuePair<byte, bool> e in p2)
          {
              r[e.Key] = e.Value;
          }
          cb.ice_response(r, p3);
      }
  
      public void opByteS_async(Test.AMD_MyClass_opByteS cb, Test.ByteS p1, Test.ByteS p2, Ice.Current current)
      {
          Test.ByteS p3 = new Test.ByteS();
          for(int i = 0; i < p1.Count; i++)
          {
              p3.Add(p1[p1.Count - (i + 1)]);
          }
  
          Test.ByteS r = new Test.ByteS();
          r.AddRange(p1);
          r.AddRange(p2);
          cb.ice_response(r, p3);
      }
  
      public void opByteSS_async(Test.AMD_MyClass_opByteSS cb, Test.ByteSS p1, Test.ByteSS p2,
                                 Ice.Current current)
      {
          Test.ByteSS p3 = new Test.ByteSS();
          for(int i = 0; i < p1.Count; i++)
          {
              p3.Add(p1[p1.Count - (i + 1)]);
          }
  
          Test.ByteSS r = new Test.ByteSS();
          r.AddRange(p1);
          r.AddRange(p2);
          cb.ice_response(r, p3);
      }
  
      public void opFloatDouble_async(Test.AMD_MyClass_opFloatDouble cb, float p1, double p2,
                                      Ice.Current current)
      {
          cb.ice_response(p2, p1, p2);
      }
  
      public void opFloatDoubleS_async(Test.AMD_MyClass_opFloatDoubleS cb, Test.FloatS p1, Test.DoubleS p2,
                                       Ice.Current current)
      {
          Test.FloatS p3 = p1;
          Test.DoubleS p4 = new Test.DoubleS();
          for(int i = 0; i < p2.Count; i++)
          {
              p4.Add(p2[p2.Count - (i + 1)]);
          }
          Test.DoubleS r = new Test.DoubleS();
          r.AddRange(p2);
          for(int i = 0; i < p1.Count; i++)
          {
              r.Add(p1[i]);
          }
          cb.ice_response(r, p3, p4);
      }
  
      public void opFloatDoubleSS_async(Test.AMD_MyClass_opFloatDoubleSS cb, Test.FloatSS p1, Test.DoubleSS p2,
                                        Ice.Current current)
      {
          Test.FloatSS p3 = p1;
          Test.DoubleSS p4 = new Test.DoubleSS();
          for(int i = 0; i < p2.Count; i++)
          {
              p4.Add(p2[p2.Count - (i + 1)]);
          }
          Test.DoubleSS r = new Test.DoubleSS();
          r.AddRange(p2);
          r.AddRange(p2);
          cb.ice_response(r, p3, p4);
      }
  
      public void opLongFloatD_async(Test.AMD_MyClass_opLongFloatD cb, Dictionary<long, float> p1,
                                     Dictionary<long, float> p2, Ice.Current current)
      {
  
gt:         Dictionary<long, float> p3 = p1;