home *** CD-ROM | disk | FTP | other *** search
- //==========================================================================
- // File: MyHost.cs
- //
- // Summary: This file provides a hosting environment for Managed Remoting
- // Objects. It uses a configuration file is used to configure:
- // Channels, WellKnown Objects, etc.
- //
- // Channels can also be registerd by calling:
- // ChannelServices.RegisterChannel
- //
- // Classes: MyHost
- //
- //--------------------------------------------------------------------------
- // This file is part of the Microsoft NGWS Samples.
- //
- // Copyright (C) 1999 Microsoft Corporation. All rights reserved.
- //==========================================================================
-
- using System;
- using System.IO;
- using System.Runtime.Remoting;
-
- public class MyHost
- {
- public static void Main(string[] args)
- {
- int ret = Initialize(args);
- if (ret != 0)
- return;
-
- Console.WriteLine("MyHost is ready to process remote messages.");
-
- String keyState = "";
- while (String.Compare(keyState,"0", true) != 0)
- {
- Console.WriteLine("Press a key and ENTER: G=GC.Collect, 0=Exit");
- keyState = Console.ReadLine();
-
- Console.WriteLine("Pressed: " + keyState);
-
- // Force a GC
- if (String.Compare(keyState,"G", true) == 0)
- {
- Console.WriteLine("GC Collect - start");
- GC.Collect();
- GC.WaitForPendingFinalizers();
- Console.WriteLine("GC Collect - done");
- }
- }
- }
-
- public static int Initialize(String[] args)
- {
- if (args.Length == 0)
- {
- Usage();
- return -1;
- }
-
- for (int i=0;i<args.Length;i++)
- {
- if (
- String.Compare(args[i],"HELP", true) == 0 ||
- String.Compare(args[i],"?", true) == 0 ||
- String.Compare(args[i],"/h", true) == 0 ||
- String.Compare(args[i],"-h", true) == 0 ||
- String.Compare(args[i],"-?", true) == 0 ||
- String.Compare(args[i],"/?", true) == 0
- )
- {
- Usage();
- return -1;
- }
-
- // Load Configuration
- if (args[i].CompareTo("-cfg")==0)
- {
- RemotingServices.ConfigureRemoting(args[i+1]);
- }
- }
-
- return 0;
- }
-
- public static void Usage()
- {
- Console.WriteLine("Usage: MyHost [-cfg ConfigFileName.cfg]\n");
- Console.WriteLine("Examples : MyHost -cfg MyHost.cfg");
- }
-
-
- }
-
-
-
-