IdlingCommands.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:IdlingCommands
  3. * 作者:xulisong
  4. * 创建时间: 2019/1/3 17:22:01
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.UI;
  13. namespace FWindSoft.Revit
  14. {
  15. /// <summary>
  16. /// 空闲命令消费者队列
  17. /// </summary>
  18. public class IdlingCommands
  19. {
  20. internal IdlingCommands()
  21. {
  22. Commands = new Queue<IdlingCommand>();
  23. }
  24. #region 生产消费队列维护
  25. /// <summary>
  26. /// 命令队列
  27. /// </summary>
  28. private readonly Queue<IdlingCommand> Commands;
  29. /// <summary>
  30. /// 在队列中加入command
  31. /// </summary>
  32. /// <param name="command"></param>
  33. public void Enqueue(IdlingCommand command)
  34. {
  35. lock (Commands)
  36. {
  37. Commands.Enqueue(command);
  38. }
  39. }
  40. /// <summary>
  41. /// 获取队列中的command
  42. /// </summary>
  43. /// <returns></returns>
  44. public IdlingCommand Dequeue()
  45. {
  46. IdlingCommand command = null;
  47. lock (Commands)
  48. {
  49. if (HasCommand)
  50. {
  51. command = Commands.Dequeue(); ;
  52. }
  53. }
  54. return command;
  55. }
  56. public bool HasCommand
  57. {
  58. get
  59. {
  60. return Commands.Count > 0;
  61. }
  62. }
  63. #endregion
  64. }
  65. }