OperationCanceledException.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. /*============================================================
  5. **
  6. **
  7. **
  8. ** Purpose: Exception for cancelled IO requests.
  9. **
  10. **
  11. ===========================================================*/
  12. using System;
  13. using System.Runtime.Serialization;
  14. using System.Threading;
  15. namespace System
  16. {
  17. [Serializable]
  18. [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  19. public class OperationCanceledException : SystemException
  20. {
  21. [NonSerialized]
  22. private CancellationToken _cancellationToken;
  23. public CancellationToken CancellationToken
  24. {
  25. get { return _cancellationToken; }
  26. private set { _cancellationToken = value; }
  27. }
  28. public OperationCanceledException()
  29. : base(SR.OperationCanceled)
  30. {
  31. HResult = HResults.COR_E_OPERATIONCANCELED;
  32. }
  33. public OperationCanceledException(string message)
  34. : base(message)
  35. {
  36. HResult = HResults.COR_E_OPERATIONCANCELED;
  37. }
  38. public OperationCanceledException(string message, Exception innerException)
  39. : base(message, innerException)
  40. {
  41. HResult = HResults.COR_E_OPERATIONCANCELED;
  42. }
  43. public OperationCanceledException(CancellationToken token)
  44. : this()
  45. {
  46. CancellationToken = token;
  47. }
  48. public OperationCanceledException(string message, CancellationToken token)
  49. : this(message)
  50. {
  51. CancellationToken = token;
  52. }
  53. public OperationCanceledException(string message, Exception innerException, CancellationToken token)
  54. : this(message, innerException)
  55. {
  56. CancellationToken = token;
  57. }
  58. protected OperationCanceledException(SerializationInfo info, StreamingContext context) : base(info, context)
  59. {
  60. }
  61. }
  62. }