Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 1c76f3a

Browse files
author
ColinA-MSFT
committed
Fix PWM.Dispose to ensure the internal Dispose method is called exactly once.
1 parent 9f565a2 commit 1c76f3a

File tree

1 file changed

+10
-2
lines changed
  • Framework/Core/Native_Hardware/Native_PWM

1 file changed

+10
-2
lines changed

Framework/Core/Native_Hardware/Native_PWM/PWM.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.SPOT.Hardware;
33
using System.Runtime.CompilerServices;
44

5-
65
namespace Microsoft.SPOT.Hardware
76
{
87
/// <summary>
@@ -43,6 +42,10 @@ public enum ScaleFactor : uint
4342
/// Scale of the period/duration (mS, uS, nS)
4443
/// </summary>
4544
private ScaleFactor m_scale;
45+
/// <summary>
46+
/// Whether this object has been disposed.
47+
/// </summary>
48+
private bool m_disposed = false;
4649

4750
//--//
4851

@@ -129,7 +132,12 @@ public PWM(Cpu.PWMChannel channel, uint period, uint duration, ScaleFactor scale
129132
/// </summary>
130133
public void Dispose()
131134
{
132-
Dispose(true);
135+
if (!m_disposed)
136+
{
137+
Dispose(true);
138+
GC.SuppressFinalize(this);
139+
m_disposed = true;
140+
}
133141
}
134142

135143
/// <summary>

0 commit comments

Comments
 (0)