home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Remoting / HelloService / MyHost.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  2.7 KB  |  98 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.     }
  53.  
  54.     public static int Initialize(String[] args)
  55.     {
  56.         if (args.Length == 0)
  57.         {
  58.             Usage();
  59.             return -1;
  60.         }
  61.  
  62.         for (int i=0;i<args.Length;i++)
  63.         {
  64.             if (
  65.                String.Compare(args[i],"HELP", true) == 0 ||
  66.                String.Compare(args[i],"?", true) == 0 ||
  67.                String.Compare(args[i],"/h", true) == 0 ||
  68.                String.Compare(args[i],"-h", true) == 0 ||
  69.                String.Compare(args[i],"-?", true) == 0 ||
  70.                String.Compare(args[i],"/?", true) == 0
  71.                )
  72.             {
  73.                 Usage();
  74.                 return -1;
  75.             }
  76.  
  77.             // Load Configuration
  78.             if (args[i].CompareTo("-cfg")==0)
  79.             {
  80.                 RemotingServices.ConfigureRemoting(args[i+1]);
  81.             }
  82.         }
  83.  
  84.         return 0;
  85.     }
  86.  
  87.     public static void Usage()
  88.     {
  89.         Console.WriteLine("Usage: MyHost [-cfg ConfigFileName.cfg]\n");
  90.         Console.WriteLine("Examples : MyHost -cfg MyHost.cfg");
  91.     }
  92.  
  93.  
  94. }
  95.  
  96.  
  97.  
  98.