///// <summary> ///// 获取一个线程并执行任务 ///// </summary> ///// <typeparam name="parameterType">参数类型</typeparam> ///// <param name="task">任务委托</param> ///// <param name="parameter">线程参数</param> //internal void FastStart<parameterType>(pushPool<parameterType> task, ref parameterType parameter) //{ // runPushPool<parameterType> run = runPushPool<parameterType>.Pop(); // run.Set(task, ref parameter); // FastStart(run, fastCSharp.threading.thread.callType.Run); //} /// <summary> /// 获取一个线程并执行任务 /// </summary> /// <param name="task">任务委托</param> /// <param name="domainUnload">应用程序退出处理</param> /// <param name="onError">应用程序退出处理</param> private void start(Action task, Action <Exception> onError, Action domainUnload) { if (task == null) { log.Error.Throw(null, "缺少 线程委托", false); } if (isDisposed) { log.Default.Real("线程池已经被释放", null, false); } else if (domainUnload == null) { if (onError == null) { FastStart(task); } else { FastStart(task, onError); } } else { thread thread = threads.Pop(); if (thread == null) { new thread(this, stackSize, task, onError, domainUnload, threading.thread.callType.Action, onError == null ? threading.thread.errorType.None : threading.thread.errorType.Action, fastCSharp.domainUnload.unloadType.Action); } else { thread.RunTask(task, onError, domainUnload, threading.thread.callType.Action, onError == null ? threading.thread.errorType.None : threading.thread.errorType.Action, fastCSharp.domainUnload.unloadType.Action); } } }
/// <summary> /// 获取一个线程并执行任务 /// </summary> /// <param name="task">任务委托</param> /// <param name="domainUnload">应用程序退出处理</param> /// <param name="onError">应用程序退出处理</param> /// <returns>线程池线程</returns> private thread start(action task, action domainUnload, action <Exception> onError) { if (task == null) { log.Default.Throw(null, "缺少 线程委托", false); } bool isDisposed; thread thread = null; while (Interlocked.CompareExchange(ref threadLock, 1, 0) != 0) { Thread.Sleep(1); } try { if (!(isDisposed = this.isDisposed) && threads.Count != 0) { thread = threads.Pop(); } } finally { threadLock = 0; } if (isDisposed) { log.Default.Add("线程池已经被释放", true, false); } else { if (thread == null) { thread = new thread(this, stackSize); } thread.RunTask(task, domainUnload, onError); } return(thread); }
internal void FastStart(object task, object onError, fastCSharp.threading.thread.callType taskType, threading.thread.errorType errorType) { thread thread = threads.Pop(); if (thread == null) { new thread(this, stackSize, task, onError, taskType, errorType); } else { thread.RunTask(task, onError, taskType, errorType); } }
internal void Push(thread thread) { if (isDisposed) { thread.Stop(); } else { threads.Push(thread); if (isDisposed) { disposePool(); } } }
internal void FastStart(Action task, Action <Exception> onError) { if (onError == null) { FastStart(task); } else { thread thread = threads.Pop(); if (thread == null) { new thread(this, stackSize, task, onError, threading.thread.callType.Action, threading.thread.errorType.Action); } else { thread.RunTask(task, onError, threading.thread.callType.Action, threading.thread.errorType.Action); } } }
/// <summary> /// 线程入池 /// </summary> /// <param name="thread">线程池线程</param> internal void Push(thread thread) { while (Interlocked.CompareExchange(ref threadLock, 1, 0) != 0) { Thread.Sleep(1); } try { if (isDisposed) { thread.Stop(); } else { threads.Add(thread); } } finally { threadLock = 0; } }