The Labs \ Source Viewer \ SSCLI \ System \ ConsoleCancelEventArgs

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*=============================================================================
  16. **
  17. ** Class: ConsoleCancelEventArgs
  18. **
  19. **
  20. ** Purpose: This class provides support goop for hooking Control-C and
  21. **          Control-Break, then preventing Control-C from interrupting the
  22. **          process.
  23. **
  24. **
  25. =============================================================================*/
  26. namespace System
  27. {
  28.     using System;
  29.    
  30.     public delegate void ConsoleCancelEventHandler(object sender, ConsoleCancelEventArgs e);
  31.    
  32.    
  33.     [Serializable()]
  34.     public sealed class ConsoleCancelEventArgs : EventArgs
  35.     {
  36.         private ConsoleSpecialKey _type;
  37.         private bool _cancel;
  38.         // Whether to cancel the CancelKeyPress event
  39.         internal ConsoleCancelEventArgs(ConsoleSpecialKey type)
  40.         {
  41.             _type = type;
  42.             _cancel = false;
  43.         }
  44.        
  45.         // Whether to cancel the break event. By setting this to true, the
  46.         // Control-C will not kill the process.
  47.         public bool Cancel {
  48.             get { return _cancel; }
  49.             set {
  50.                 if (_type == ConsoleSpecialKey.ControlBreak && value == true)
  51.                     throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CantCancelCtrlBreak"));
  52.                 _cancel = value;
  53.             }
  54.         }
  55.        
  56.         public ConsoleSpecialKey SpecialKey {
  57.             get { return _type; }
  58.         }
  59.     }
  60. }

Developer Fusion