Browse Source

Added code to debug disposables

pull/261/head
Nikita Tsukanov 10 years ago
parent
commit
6c77e2b236
  1. 16
      src/Perspex.Base/PerspexDisposable.cs
  2. 1
      src/Perspex.Base/Platform/IPclPlatformWrapper.cs
  3. BIN
      src/Shared/PlatformSupport/PclPlatformWrapper.cs

16
src/Perspex.Base/PerspexDisposable.cs

@ -3,23 +3,37 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Perspex.Platform;
namespace Perspex
{
public abstract class PerspexDisposable : IDisposable
{
#if DEBUG_DISPOSE
public string DisposedAt { get; private set; }
#endif
public bool IsDisposed { get; private set; }
public void Dispose()
{
IsDisposed = true;
#if DEBUG_DISPOSE
DisposedAt = PerspexLocator.Current.GetService<IPclPlatformWrapper>().GetStackTrace();
#endif
DoDispose();
}
protected void CheckDisposed()
{
if (IsDisposed)
throw new ObjectDisposedException(GetType().FullName);
throw new ObjectDisposedException(GetType().FullName
#if DEBUG_DISPOSE
, "Disposed at: \n" + DisposedAt
#endif
);
}
protected abstract void DoDispose();

1
src/Perspex.Base/Platform/IPclPlatformWrapper.cs

@ -12,5 +12,6 @@ namespace Perspex.Platform
Assembly[] GetLoadedAssemblies();
void PostThreadPoolItem(Action cb);
IDisposable StartSystemTimer(TimeSpan interval, Action tick);
string GetStackTrace();
}
}

BIN
src/Shared/PlatformSupport/PclPlatformWrapper.cs

Binary file not shown.
Loading…
Cancel
Save