当前位置: 首页>>代码示例>>C#>>正文


C# IWorkItemResult类代码示例

本文整理汇总了C#中IWorkItemResult的典型用法代码示例。如果您正苦于以下问题:C# IWorkItemResult类的具体用法?C# IWorkItemResult怎么用?C# IWorkItemResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IWorkItemResult类属于命名空间,在下文中一共展示了IWorkItemResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: test

        public void test()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
            GlobalVar.isCrawling = true;
            //string conn = string.Format(@"Data Source="+System.Environment.CurrentDirectory+"\\data\\{0}", GlobalVar.filename);
            sqlitehelper con = new sqlitehelper(System.Environment.CurrentDirectory + @"\data\" + GlobalVar.filename);
            string sql = "select keyword from Content where flag==0";
            DataTable dt = new DataTable();
            dt = con.GetDataTable(sql);
            IWorkItemResult[] wir = new IWorkItemResult[dt.Rows.Count];
            MessageBox.Show(dt.Rows.Count.ToString());
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //MessageBox.Show(dt.Rows[i]["keyword"].ToString());
                OneWorker one = new OneWorker(dt.Rows[i]["keyword"].ToString());
                ThreadPool.QueueUserWorkItem(one.work, i);

            }

            bool success = SmartThreadPool.WaitAll(
                   wir);

            if (success)
            {
                GlobalVar.isCrawling = false;

            }
            smartThreadPool.Shutdown();
        }
开发者ID:shellleyma,项目名称:sescraper,代码行数:31,代码来源:ThreadControl.cs

示例2: WaitAllT

        public void WaitAllT()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            bool success = true;

            IWorkItemResult<int>[] wirs = new IWorkItemResult<int>[5];

            for (int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] = smartThreadPool.QueueWorkItem(new Func<int, int, int>(System.Math.Min), i, i + 1);
            }

            SmartThreadPool.WaitAll(wirs);

            for (int i = 0; i < wirs.Length; ++i)
            {
                if (!wirs[i].IsCompleted)
                {
                    success = false;
                    break;
                }

                int result = wirs[i].GetResult();
                if (i != result)
                {
                    success = false;
                    break;
                }
            }

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:35,代码来源:TestMultipleWorkItems.cs

示例3: WaitAny

		public void WaitAny() 
		{ 
			SmartThreadPool smartThreadPool = new SmartThreadPool();
			IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);

			bool success = false;

			IWorkItemResult [] wirs = new IWorkItemResult[5];

			for(int i = 0; i < wirs.Length; ++i)
			{
				wirs[i] = 
					workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
			}

			int index = SmartThreadPool.WaitAny(wirs);

			if (wirs[index].IsCompleted)
			{
				int result = (int)wirs[index].GetResult();
				if (1 == result)
				{
					success = true;
				}
			}

			smartThreadPool.Shutdown();

			Assert.IsTrue(success);
		} 
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:30,代码来源:TestWIGMultipleWorkItems.cs

示例4: Start

        /// <summary>
        /// Starts the tasks execution.
        /// </summary>
        /// <returns>If has reach the timeout false, otherwise true.</returns>
        public override bool Start()
        {
            base.Start();
            m_threadPool = new SmartThreadPool();

            try
            {
                m_threadPool.MinThreads = MinThreads;
                m_threadPool.MaxThreads = MaxThreads;
                var workItemResults = new IWorkItemResult[Tasks.Count];

                for (int i = 0; i < Tasks.Count; i++)
                {
                    var t = Tasks[i];
                    workItemResults[i] = m_threadPool.QueueWorkItem(new WorkItemCallback(Run), t);
                }

                m_threadPool.Start();

                // Timeout was reach?
                if (!m_threadPool.WaitForIdle(Timeout.TotalMilliseconds > int.MaxValue ? int.MaxValue : Convert.ToInt32(Timeout.TotalMilliseconds)))
                {
                    if (m_threadPool.IsShuttingdown)
                    {
                        return true;
                    }
                    else
                    {
                        m_threadPool.Cancel(true);
                        return false;
                    }
                }

                foreach (var wi in workItemResults)
                {
                    Exception ex;
                    wi.GetResult(out ex);

                    if (ex != null)
                    {
                        throw ex;
                    }
                }

                return true;
            }
            finally
            {
                m_threadPool.Shutdown(true, 1000);
                m_threadPool.Dispose();
                IsRunning = false;
            }
        }
开发者ID:denisbarboni,项目名称:Projeto-AG,代码行数:57,代码来源:SmartThreadPoolTaskExecutor.cs

示例5: WaitAllWithTimeoutFailure

        public void WaitAllWithTimeoutFailure()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();
            IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);

            IWorkItemResult [] wirs = new IWorkItemResult[5];

            for(int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] =
                    workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
            }

            bool timeout = !SmartThreadPool.WaitAll(wirs, 10, true);
            bool success = timeout;

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:20,代码来源:TestWIGMultipleWorkItems.cs

示例6: WaitAll

        public void WaitAll()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            bool success = true;

            IWorkItemResult [] wirs = new IWorkItemResult[5];

            for(int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] =
                    smartThreadPool.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
            }

            SmartThreadPool.WaitAll(wirs);

            for(int i = 0; i < wirs.Length; ++i)
            {
                if (!wirs[i].IsCompleted)
                {
                    success = false;
                    break;
                }
                else
                {
                    int result = (int)wirs[i].GetResult();
                    if (1 != result)
                    {
                        success = false;
                        break;
                    }
                }
            }

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:38,代码来源:TestMultipleWorkItems.cs

示例7: DoWork

		public void DoWork() 
		{ 
			SmartThreadPool smartThreadPool = new SmartThreadPool();

			IWorkItemResult wir1 = 
				smartThreadPool.QueueWorkItem(new 
				WorkItemCallback(this.DoSomeWork1), null);

			IWorkItemResult wir2 = 
				smartThreadPool.QueueWorkItem(new 
				WorkItemCallback(this.DoSomeWork2), null);

			IWorkItemResult [] wirs = new IWorkItemResult [] { wir1, wir2 };

			int index = SmartThreadPool.WaitAny(wirs);

			if (index != WaitHandle.WaitTimeout)
			{
				int result = (int)wirs[index].Result;
			}

			smartThreadPool.Shutdown();
		} 
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:23,代码来源:WaitForAnyExample.cs

示例8: ReleaseWaitHandles

		/// <summary>
		/// Release the work items' wait handles
		/// </summary>
		/// <param name="workItemResults">An array of work item results</param>
		private static void ReleaseWaitHandles(IWorkItemResult [] workItemResults)
		{
			for(int i = 0; i < workItemResults.Length; ++i)
			{
				WorkItemResult wir = workItemResults[i] as WorkItemResult;

				wir.GetWorkItem().ReleaseWaitHandle();
			}
		}
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:13,代码来源:WorkItem.cs

示例9: GetWaitHandles

		/// <summary>
		/// Fill an array of wait handles with the work items wait handles.
		/// </summary>
		/// <param name="workItemResults">An array of work item results</param>
		/// <param name="waitHandles">An array of wait handles to fill</param>
		private static void GetWaitHandles(
			IWorkItemResult [] workItemResults,
			WaitHandle [] waitHandles)
		{
			for(int i = 0; i < workItemResults.Length; ++i)
			{
				WorkItemResult wir = workItemResults[i] as WorkItemResult;
				Debug.Assert(null != wir, "All workItemResults must be WorkItemResult objects");

				waitHandles[i] = wir.GetWorkItem().GetWaitHandle();
			}
		}
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:17,代码来源:WorkItem.cs

示例10: WaitAny

		/// <summary>
		/// Waits for any of the work items in the specified array to complete, cancel, or timeout
		/// </summary>
		/// <param name="workItemResults">Array of work item result objects</param>
		/// <param name="millisecondsTimeout">The number of milliseconds to wait, or Timeout.Infinite (-1) to wait indefinitely.</param>
		/// <param name="exitContext">
		/// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. 
		/// </param>
		/// <param name="cancelWaitHandle">A cancel wait handle to interrupt the wait if needed</param>
		/// <returns>
		/// The array index of the work item result that satisfied the wait, or WaitTimeout if no work item result satisfied the wait and a time interval equivalent to millisecondsTimeout has passed or the work item has been canceled.
		/// </returns>
		internal static int WaitAny(			
			IWorkItemResult [] workItemResults,
			int millisecondsTimeout,
			bool exitContext,
			WaitHandle cancelWaitHandle)
		{
			WaitHandle [] waitHandles = null;

			if (null != cancelWaitHandle)
			{
				waitHandles = new WaitHandle[workItemResults.Length+1];
				GetWaitHandles(workItemResults, waitHandles);
				waitHandles[workItemResults.Length] = cancelWaitHandle;
			}
			else
			{
				waitHandles = new WaitHandle[workItemResults.Length];
				GetWaitHandles(workItemResults, waitHandles);
			}

			int result = WaitHandle.WaitAny(waitHandles, millisecondsTimeout, exitContext);

			// Treat cancel as timeout
			if (null != cancelWaitHandle)
			{
				if (result == workItemResults.Length)
				{
					result = WaitHandle.WaitTimeout;
				}
			}

			ReleaseWaitHandles(workItemResults);

			return result;
		}
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:47,代码来源:WorkItem.cs

示例11: WaitAll

		/// <summary>
		/// Wait for all work items to complete
		/// </summary>
		/// <param name="workItemResults">Array of work item result objects</param>
		/// <param name="millisecondsTimeout">The number of milliseconds to wait, or Timeout.Infinite (-1) to wait indefinitely.</param>
		/// <param name="exitContext">
		/// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. 
		/// </param>
		/// <param name="cancelWaitHandle">A cancel wait handle to interrupt the wait if needed</param>
		/// <returns>
		/// true when every work item in workItemResults has completed; otherwise false.
		/// </returns>
		internal static bool WaitAll(
			IWorkItemResult [] workItemResults,
			int millisecondsTimeout,
			bool exitContext,
			WaitHandle cancelWaitHandle)
		{
			if (0 == workItemResults.Length)
			{
				return true;
			}

			bool success;
			WaitHandle [] waitHandles = new WaitHandle[workItemResults.Length];;
			GetWaitHandles(workItemResults, waitHandles);

			if ((null == cancelWaitHandle) && (waitHandles.Length <= 64))
			{
				success = WaitHandle.WaitAll(waitHandles, millisecondsTimeout, exitContext);
			}
			else
			{
				success = true;
				int millisecondsLeft = millisecondsTimeout;
				DateTime start = DateTime.Now;

				WaitHandle [] whs;
				if (null != cancelWaitHandle)
				{
					whs = new WaitHandle [] { null, cancelWaitHandle };
				}
				else
				{
					whs = new WaitHandle [] { null };
				}

                bool waitInfinitely = (Timeout.Infinite == millisecondsTimeout);
				// Iterate over the wait handles and wait for each one to complete.
				// We cannot use WaitHandle.WaitAll directly, because the cancelWaitHandle
				// won't affect it.
				// Each iteration we update the time left for the timeout.
				for(int i = 0; i < workItemResults.Length; ++i)
				{
                    // WaitAny don't work with negative numbers
                    if (!waitInfinitely && (millisecondsLeft < 0))
                    {
                        success = false;
                        break;
                    }

					whs[0] = waitHandles[i];
					int result = WaitHandle.WaitAny(whs, millisecondsLeft, exitContext);
					if ((result > 0) || (WaitHandle.WaitTimeout == result))
					{
						success = false;
						break;
					}

					if (!waitInfinitely)
					{
                        // Update the time left to wait
						TimeSpan ts = DateTime.Now - start;
						millisecondsLeft = millisecondsTimeout - (int)ts.TotalMilliseconds;
					}
				}
			}
			// Release the wait handles
			ReleaseWaitHandles(workItemResults);

			return success;
		}
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:82,代码来源:WorkItem.cs

示例12: XWorkItem

 public XWorkItem(IWorkItemResult w)
 {
     wr = w;
 }
开发者ID:BackupTheBerlios,项目名称:seleon,代码行数:4,代码来源:XWorkItem.cs

示例13: DoPostExecute

 private void DoPostExecute(IWorkItemResult wir)
 {
 }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:3,代码来源:TestWIGChainedDelegates.cs

示例14: DoSomePostExecuteWork

		private void DoSomePostExecuteWork(IWorkItemResult wir)
		{ 
			PostExecuteResult postExecuteResult = wir.State as PostExecuteResult;
			postExecuteResult.wh.Set();
		}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:5,代码来源:TestPostExecute.cs

示例15: WaitAnyT

        public void WaitAnyT()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            bool success = false;

            IWorkItemResult<int>[] wirs = new IWorkItemResult<int>[5];

            for (int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] = smartThreadPool.QueueWorkItem(new Func<int, int, int>(Math.Max), i, i - 1);
            }

            int index = SmartThreadPool.WaitAny(wirs);

            if (wirs[index].IsCompleted)
            {
                int result = wirs[index].GetResult();
                if (index == result)
                {
                    success = true;
                }
            }

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:28,代码来源:TestMultipleWorkItems.cs


注:本文中的IWorkItemResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。