AbandonedMutexException.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // AbandonedMutexException
  6. // Thrown when a wait completes because one or more mutexes was abandoned.
  7. // AbandonedMutexs indicate serious error in user code or machine state.
  8. ////////////////////////////////////////////////////////////////////////////////
  9. using System;
  10. using System.Threading;
  11. using System.Runtime.InteropServices;
  12. using System.Runtime.Serialization;
  13. namespace System.Threading
  14. {
  15. [Serializable]
  16. [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  17. public class AbandonedMutexException : SystemException
  18. {
  19. private int _mutexIndex = -1;
  20. private Mutex _mutex = null;
  21. public AbandonedMutexException()
  22. : base(SR.Threading_AbandonedMutexException)
  23. {
  24. HResult = HResults.COR_E_ABANDONEDMUTEX;
  25. }
  26. public AbandonedMutexException(string message)
  27. : base(message)
  28. {
  29. HResult = HResults.COR_E_ABANDONEDMUTEX;
  30. }
  31. public AbandonedMutexException(string message, Exception inner)
  32. : base(message, inner)
  33. {
  34. HResult = HResults.COR_E_ABANDONEDMUTEX;
  35. }
  36. public AbandonedMutexException(int location, WaitHandle handle)
  37. : base(SR.Threading_AbandonedMutexException)
  38. {
  39. HResult = HResults.COR_E_ABANDONEDMUTEX;
  40. SetupException(location, handle);
  41. }
  42. public AbandonedMutexException(string message, int location, WaitHandle handle)
  43. : base(message)
  44. {
  45. HResult = HResults.COR_E_ABANDONEDMUTEX;
  46. SetupException(location, handle);
  47. }
  48. public AbandonedMutexException(string message, Exception inner, int location, WaitHandle handle)
  49. : base(message, inner)
  50. {
  51. HResult = HResults.COR_E_ABANDONEDMUTEX;
  52. SetupException(location, handle);
  53. }
  54. protected AbandonedMutexException(SerializationInfo info, StreamingContext context)
  55. : base(info, context)
  56. {
  57. }
  58. private void SetupException(int location, WaitHandle handle)
  59. {
  60. _mutexIndex = location;
  61. if (handle != null)
  62. _mutex = handle as Mutex;
  63. }
  64. public Mutex Mutex => _mutex;
  65. public int MutexIndex => _mutexIndex;
  66. }
  67. }