Ejemplo n.º 1
0
 /// <summary>
 /// Start
 /// </summary>
 public static void Start()
 {
     TraceLog.ReleaseWriteDebug("Sql write queue start init...");
     MessageQueueSection section = GetSection();
     SlaveMessageQueue = section.SlaveMessageQueue;
     if (_queueWatchTimers != null && _queueWatchTimers.Length != section.SqlSyncQueueNum)
     {
         foreach (var timer in _queueWatchTimers)
         {
             try
             {
                 timer.Dispose();
             }
             catch (Exception ex)
             {
                 TraceLog.WriteError("Sql write queue stop error:{0}", ex);
             }
         }
         _queueWatchTimers = null;
     }
     if (_queueWatchTimers == null)
     {
         _isWatchWorking = new int[section.SqlSyncQueueNum];
         _queueWatchTimers = new Timer[_isWatchWorking.Length];
         for (int i = 0; i < _queueWatchTimers.Length; i++)
         {
             _queueWatchTimers[i] = new Timer(OnCheckSqlSyncQueue, i, 100, 100);
         }
         _threadPools = new SmartThreadPool(180 * 1000, 100, 5);
         _threadPools.Start();
     }
 }
Ejemplo n.º 2
0
        public void ThreadTest()
        {
            var _threadPools = new SmartThreadPool(180 * 1000, 100, 5);
            _threadPools.Start();

            var result = _threadPools.QueueWorkItem(() =>
            {
                Thread.Sleep(5000);
            });
            while (!result.IsCompleted)
            {
                Thread.Sleep(100);
                Trace.WriteLine("wait...");
            }
            Trace.WriteLine(result.Result);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="WorkItemsGroup"/> class.
		/// </summary>
		/// <param name="stp">Stp.</param>
		/// <param name="concurrency">Concurrency.</param>
		/// <param name="wigStartInfo">Wig start info.</param>
	    public WorkItemsGroup(
			SmartThreadPool stp, 
			int concurrency, 
			WIGStartInfo wigStartInfo)
		{
			if (concurrency <= 0)
			{
				throw new ArgumentOutOfRangeException(
                    "concurrency",
#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE)
                    concurrency,
#endif
 "concurrency must be greater than zero");
			}
			_stp = stp;
			_concurrency = concurrency;
			_workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly();
			_workItemsQueue = new PriorityQueue();
	        Name = "WorkItemsGroup";

			// The _workItemsInStpQueue gets the number of currently executing work items,
			// because once a work item is executing, it cannot be cancelled.
			_workItemsInStpQueue = _workItemsExecutingInStp;

            _isSuspended = _workItemsGroupStartInfo.StartSuspended;
		}
Ejemplo n.º 4
0
 public ThreadEntry(SmartThreadPool stp)
 {
     _associatedSmartThreadPool = stp;
     _creationTime = DateTime.UtcNow;
     _lastAliveTime = DateTime.MinValue;
 }