home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Remoting / CallContext / MyHost.cs < prev   
Encoding:
Text File  |  2000-06-23  |  2.7 KB  |  96 lines

  1. //==========================================================================
  2. //  File:       MyHost.cs
  3. //
  4. //  Summary:    This file provides a hosting environment for Managed Remoting 
  5. //            Objects. It uses a configuration file is used to configure:
  6. //                  Channels, WellKnown Objects, etc.
  7. //
  8. //            Channels can also be registerd by calling:
  9. //            ChannelServices.RegisterChannel
  10. //
  11. //  Classes:    MyHost
  12. //
  13. //--------------------------------------------------------------------------
  14. //  This file is part of the Microsoft NGWS Samples.
  15. //
  16. //  Copyright (C) 1999 Microsoft Corporation.  All rights reserved.
  17. //==========================================================================
  18.  
  19. using System;
  20. using System.IO;
  21. using System.Runtime.Remoting;
  22.  
  23. public class MyHost
  24. {
  25.     public static void Main(string[] args)
  26.     {
  27.         int ret = Initialize(args);
  28.         if (ret != 0)
  29.             return;
  30.  
  31.         Console.WriteLine("MyHost is ready to process remote messages.");
  32.  
  33.         String keyState = "";
  34.         while (String.Compare(keyState,"0", true) != 0)
  35.         {
  36.             Console.WriteLine("Press a key and ENTER: G=GC.Collect, 0=Exit");
  37.             keyState = Console.ReadLine();
  38.  
  39.             Console.WriteLine("Pressed: " + keyState);
  40.  
  41.             // Force a GC
  42.             if (String.Compare(keyState,"G", true) == 0)
  43.             {
  44.                 Console.WriteLine("GC Collect - start");
  45.                 GC.Collect();
  46.                 GC.WaitForPendingFinalizers();
  47.                 Console.WriteLine("GC Collect - done");
  48.             }
  49.         }
  50.     }
  51.  
  52.     public static int Initialize(String[] args)
  53.     {
  54.         if (args.Length == 0)
  55.         {
  56.             Usage();
  57.             return -1;
  58.         }
  59.  
  60.         for (int i=0;i<args.Length;i++)
  61.         {
  62.             if (
  63.                String.Compare(args[i],"HELP", true) == 0 ||
  64.                String.Compare(args[i],"?", true) == 0 ||
  65.                String.Compare(args[i],"/h", true) == 0 ||
  66.                String.Compare(args[i],"-h", true) == 0 ||
  67.                String.Compare(args[i],"-?", true) == 0 ||
  68.                String.Compare(args[i],"/?", true) == 0
  69.                )
  70.             {
  71.                 Usage();
  72.                 return -1;
  73.             }
  74.  
  75.             // Load Configuration
  76.             if (args[i].CompareTo("-cfg")==0)
  77.             {
  78.                 RemotingServices.ConfigureRemoting(args[i+1]);
  79.             }
  80.         }
  81.  
  82.         return 0;
  83.     }
  84.  
  85.     public static void Usage()
  86.     {
  87.         Console.WriteLine("Usage: MyHost [-cfg ConfigFileName.cfg]\n");
  88.         Console.WriteLine("Examples : MyHost -cfg MyHost.cfg");
  89.     }
  90.  
  91.  
  92. }
  93.  
  94.  
  95.  
  96.