ReentrantFlag.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. namespace Xceed.Wpf.AvalonDock.Controls
  15. {
  16. class ReentrantFlag
  17. {
  18. public class _ReentrantFlagHandler : IDisposable
  19. {
  20. ReentrantFlag _owner;
  21. public _ReentrantFlagHandler(ReentrantFlag owner)
  22. {
  23. _owner = owner;
  24. _owner._flag = true;
  25. }
  26. public void Dispose()
  27. {
  28. _owner._flag = false;
  29. }
  30. }
  31. bool _flag = false;
  32. public _ReentrantFlagHandler Enter()
  33. {
  34. if (_flag)
  35. throw new InvalidOperationException();
  36. return new _ReentrantFlagHandler(this);
  37. }
  38. public bool CanEnter
  39. {
  40. get { return !_flag; }
  41. }
  42. }
  43. }