lith 3 年 前
コミット
146ee0b6ee
41 ファイル変更665 行追加675 行削除
  1. 1 1
      Publish/ReleaseFile/docker-image/docker导入导出镜像.md
  2. 1 1
      Publish/ReleaseFile/docker-image/制作镜像Sers.md
  3. 1 1
      dotnet/Gateway/App.Gateway/App.Gateway.csproj
  4. 1 1
      dotnet/Library/Sers/Sers.CL/Ipc/Sers.CL.Ipc.NamedPipe/Doc/Sers.CL.Ipc.NamedPipe-额外命名管道/Sers.CL.Ipc.NamedPipe.csproj
  5. 1 1
      dotnet/Library/Sers/Sers.CL/Ipc/Sers.CL.Ipc.NamedPipe/Sers.CL.Ipc.NamedPipe.csproj
  6. 1 1
      dotnet/Library/Sers/Sers.CL/Ipc/Sers.CL.Ipc.SharedMemory/Sers.CL.Ipc.SharedMemory.csproj
  7. 1 1
      dotnet/Library/Sers/Sers.CL/Socket/Sers.CL.Socket.Iocp/Sers.CL.Socket.Iocp.csproj
  8. 1 1
      dotnet/Library/Sers/Sers.CL/Socket/Sers.CL.Socket.ThreadWait/Sers.CL.Socket.ThreadWait.csproj
  9. 1 1
      dotnet/Library/Sers/Sers.CL/WebSocket/Sers.CL.WebSocket/Sers.CL.WebSocket.csproj
  10. 1 1
      dotnet/Library/Sers/Sers.CL/Zmq/FullDuplex/Sers.CL.Zmq.FullDuplex/Sers.CL.Zmq.FullDuplex.csproj
  11. 1 1
      dotnet/Library/Sers/Sers.CL/Zmq/ThreadWait/Sers.CL.ClrZmq.ThreadWait/Sers.CL.ClrZmq.ThreadWait.csproj
  12. 1 1
      dotnet/Library/Sers/Sers.Core/Sers.Core.Temp/Sers.Core.Temp.csproj
  13. 1 1
      dotnet/Library/Sers/Sers.Core/Sers.Core/Sers.Core.csproj
  14. 2 5
      dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/ConsumerFactory.cs
  15. 0 63
      dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/Mode/LongTask.cs
  16. 15 8
      dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/Mode/ManagedThread.cs
  17. 2 2
      dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Util.Consumer.Test/ProgramQps.cs
  18. 1 1
      dotnet/Library/Sers/Sers.Gateway/Sers.Gateway/Sers.Gateway.csproj
  19. 1 1
      dotnet/Library/Sers/Sers.Hardware/Sers.Hardware/Sers.Hardware.csproj
  20. 1 1
      dotnet/Library/Sers/Sers.Serslot/Sers.Serslot/Sers.Serslot.csproj
  21. 1 1
      dotnet/Library/Sers/Sers.ServiceStation/Sers.ServiceStation/Sers.ServiceStation.csproj
  22. 0 67
      dotnet/Library/Vit/Vit.Core/Test/Vit.Core.Util.Threading.Worker.MsTest/Worker/LongTask_Test.cs
  23. 12 13
      dotnet/Library/Vit/Vit.Core/Test/Vit.Core.Util.Threading.Worker.MsTest/Worker/ManagedThread_Test.cs
  24. 0 146
      dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/LongTask.cs
  25. 0 333
      dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/LongTask_TimeLimit.cs
  26. 2 1
      dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/LongThread_TimeLimit.cs
  27. 572 0
      dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/ManagedThread.cs
  28. 1 1
      dotnet/Library/Vit/Vit.Core/Vit.Core/Vit.Core.csproj
  29. 1 1
      dotnet/Library/Vit/Vit.Net.Http.FormFile/Vit.Net.Http.FormFile.csproj
  30. 1 1
      dotnet/Library/Vit/Vit.WebHost/Vit.WebHost.csproj
  31. 1 1
      dotnet/ServiceCenter/App.Gover.Gateway/App.Gover.Gateway.csproj
  32. 8 8
      dotnet/ServiceCenter/App.ServiceCenter.NetFx/App.ServiceCenter.NetFx/packages.config
  33. 1 1
      dotnet/ServiceCenter/App.ServiceCenter/App.ServiceCenter.csproj
  34. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Apm/Sers.Gover.Apm.Txt/Sers.Gover.Apm.Txt.csproj
  35. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Apm/Sers.Gover.Apm.Zipkin/Sers.Gover.Apm.Zipkin.csproj
  36. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Sers.Gover.csproj
  37. 1 1
      dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter.csproj
  38. 1 1
      dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.Demo/Did.SersLoader.Demo.csproj
  39. 23 0
      dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.Demo/Program.cs
  40. 1 1
      dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.HelloWorld/Did.SersLoader.HelloWorld.csproj
  41. 1 1
      dotnet/ServiceStation/Demo/StressTest/App.Robot.Station/App.Robot.Station.csproj

+ 1 - 1
Publish/ReleaseFile/docker-image/docker导入导出镜像.md

@@ -1,5 +1,5 @@
 #导出镜像
-tag=2.1.10
+tag=2.1.11-temp
 
 docker save -o /root/image/dotnet.2.1.tar serset/dotnet:2.1
 docker save -o /root/image/sers-cgateway-1.2.0.tar serset/sers-cgateway:1.2.0

+ 1 - 1
Publish/ReleaseFile/docker-image/制作镜像Sers.md

@@ -37,7 +37,7 @@ cd /root/image
 
 
 #构建镜像并推送到 Docker Hub 
-export tag=2.1.10
+export tag=2.1.11-temp
 
 cd sers
 docker buildx build . -t serset/sers:${tag} -t serset/sers --platform=linux/amd64,linux/arm64,linux/arm/v7 --push

+ 1 - 1
dotnet/Gateway/App.Gateway/App.Gateway.csproj

@@ -8,7 +8,7 @@
 	<PropertyGroup>
 		<OutputType>Exe</OutputType>
 		<TargetFramework>netcoreapp2.1</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 		<PackageProjectUrl>https://github.com/serset/Sers</PackageProjectUrl>
 	</PropertyGroup>
 

+ 1 - 1
dotnet/Library/Sers/Sers.CL/Ipc/Sers.CL.Ipc.NamedPipe/Doc/Sers.CL.Ipc.NamedPipe-额外命名管道/Sers.CL.Ipc.NamedPipe.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
-    <Version>2.1.10</Version>
+    <Version>2.1.11-temp</Version>
     <Description>https://github.com/serset/Sers</Description>
   </PropertyGroup>
 

+ 1 - 1
dotnet/Library/Sers/Sers.CL/Ipc/Sers.CL.Ipc.NamedPipe/Sers.CL.Ipc.NamedPipe.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.CL/Ipc/Sers.CL.Ipc.SharedMemory/Sers.CL.Ipc.SharedMemory.csproj

@@ -2,7 +2,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.CL/Socket/Sers.CL.Socket.Iocp/Sers.CL.Socket.Iocp.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.CL/Socket/Sers.CL.Socket.ThreadWait/Sers.CL.Socket.ThreadWait.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.CL/WebSocket/Sers.CL.WebSocket/Sers.CL.WebSocket.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.CL/Zmq/FullDuplex/Sers.CL.Zmq.FullDuplex/Sers.CL.Zmq.FullDuplex.csproj

@@ -3,7 +3,7 @@
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
 		<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.CL/Zmq/ThreadWait/Sers.CL.ClrZmq.ThreadWait/Sers.CL.ClrZmq.ThreadWait.csproj

@@ -2,7 +2,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.Core/Sers.Core.Temp/Sers.Core.Temp.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
-    <Version>2.1.10</Version>
+    <Version>2.1.11-temp</Version>
   </PropertyGroup>
   
   <PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.Core/Sers.Core/Sers.Core.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 2 - 5
dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/ConsumerFactory.cs

@@ -21,11 +21,8 @@ namespace Sers.Core.Util.Consumer
                 case "ConsumerCascade":
                     consumer = new ConsumerCascade<T, LongThread<T>>();
                     break;
-                case "LongTask":
-                    consumer = new LongTask<T>();
-                    break;
-                case "LongTask_TimeLimit":
-                    consumer = new LongTask_TimeLimit<T>();
+                case "ManagedThread":
+                    consumer = new ManagedThread<T>();
                     break;
                 default:
                     consumer = new LongThread<T>();

+ 0 - 63
dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/Mode/LongTask.cs

@@ -1,63 +0,0 @@
-using Newtonsoft.Json.Linq;
-
-using System;
-using System.Runtime.CompilerServices;
-using Vit.Core.Util.Threading.Worker;
-using Vit.Extensions;
-
-
-
-namespace Sers.Core.Util.Consumer
-{
-
-    public class LongTask<T> : IConsumer<T>
-    {
-
-        public Action<T> Processor { get => task.Processor; set => task.Processor = value; }
-        public Action<ETaskFinishStatus, T> OnFinish { get => task.OnFinish; set => task.OnFinish = value; }
-
-
-
-        Vit.Core.Util.Threading.Worker.LongTask<T> task = new Vit.Core.Util.Threading.Worker.LongTask<T>();
-
-        public string threadName { get; set; }
-
-        public int threadCount { get => task.threadCount; set => task.threadCount = value; }
-
-        /// <summary>
-        /// 等待队列的最大长度(默认:100000)
-        /// </summary>
-        public int pendingQueueLength { get => task.pendingQueueLength; set => task.pendingQueueLength = value; }
-
-
-        public bool isRunning { get => task.IsRunning; }  
-
-
-        public void Init(JObject config)
-        {
-            threadCount = config["threadCount"]?.Deserialize<int?>() ?? 16;
-            pendingQueueLength = config["pendingQueueLength"]?.Deserialize<int?>() ?? 100000;
-        }
-
-
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public void Publish(T t)
-        {
-            task.Publish(t);
-        }
-
-
-        public void Start()
-        {
-            task.Stop();
-            task.Start();
-        }
-
-        public void Stop()
-        {
-            task.Stop();
-        }
-
-         
-    }
-}

+ 15 - 8
dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/Mode/LongTask_TimeLimit.cs → dotnet/Library/Sers/Sers.Core/Sers.Core/Util/Consumer/Mode/ManagedThread.cs

@@ -10,20 +10,26 @@ using Vit.Extensions;
 namespace Sers.Core.Util.Consumer
 {
 
-    public class LongTask_TimeLimit<T> : IConsumer<T> 
+    public class ManagedThread<T> : IConsumer<T> 
     {
 
+        Vit.Core.Util.Threading.Worker.ManagedThread<T> task = new Vit.Core.Util.Threading.Worker.ManagedThread<T>();
+
         public Action<T> Processor { get => task.Processor; set => task.Processor = value; }
         public Action<ETaskFinishStatus, T> OnFinish { get => task.OnFinish; set => task.OnFinish = value; }
 
+        public string threadName { get => task.threadName; set => task.threadName = value; }
 
-
-        Vit.Core.Util.Threading.Worker.LongTask_TimeLimit<T> task = new Vit.Core.Util.Threading.Worker.LongTask_TimeLimit<T>();
-
-        public string threadName { get; set; }
-
+        /// <summary>
+        /// 常驻线程数,默认16。可为0
+        /// </summary>
         public int threadCount { get => task.threadCount; set => task.threadCount = value; }
 
+        /// <summary>
+        /// 最大线程数(包含常驻线程和临时线程),默认100。
+        /// </summary>
+        public int maxThreadCount { get => task.maxThreadCount; set => task.maxThreadCount = value; }
+
         /// <summary>
         /// 等待队列的最大长度(默认:100000)
         /// </summary>
@@ -34,12 +40,13 @@ namespace Sers.Core.Util.Consumer
         /// </summary>
         public int timeoutMs { get => task.timeoutMs; set => task.timeoutMs = value; }
 
-        public bool isRunning { get => task.IsRunning; }  
+        public bool isRunning { get => task.IsRunning; }
 
 
         public void Init(JObject config)
         {
-            threadCount = config["threadCount"]?.Deserialize<int?>() ?? 100;
+            threadCount = config["threadCount"]?.Deserialize<int?>() ?? 16;
+            maxThreadCount = config["maxThreadCount"]?.Deserialize<int?>() ?? 100;
             pendingQueueLength = config["pendingQueueLength"]?.Deserialize<int?>() ?? 100000;
             timeoutMs = config["timeoutMs"]?.Deserialize<int?>() ?? 300000;
         }

+ 2 - 2
dotnet/Library/Sers/Sers.Core/Test/Sers.Core.Util.Consumer.Test/ProgramQps.cs

@@ -78,8 +78,8 @@ namespace CLClient
                 case "LongThread":
                     consumer = new LongThread<Product>();  //16 16 1600千            //ori:16 16 440万          2  2  800万
                     break;
-                case "LongTask":
-                    consumer = new LongTask<Product>();  //16 16 1600千   
+                case "ManagedThread":
+                    consumer = new ManagedThread<Product>();
                     break;
 
                 case "ConsumerCache_LongThread":

+ 1 - 1
dotnet/Library/Sers/Sers.Gateway/Sers.Gateway/Sers.Gateway.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.Hardware/Sers.Hardware/Sers.Hardware.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.Serslot/Sers.Serslot/Sers.Serslot.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
     <TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Sers/Sers.ServiceStation/Sers.ServiceStation/Sers.ServiceStation.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 0 - 67
dotnet/Library/Vit/Vit.Core/Test/Vit.Core.Util.Threading.Worker.MsTest/Worker/LongTask_Test.cs

@@ -1,67 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Timers;
-
-using Vit.Core.Util.Threading.Worker;
-
-namespace Vit.Core.Util.Threading.MsTest.Worker
-{
-    [TestClass]
-    public class LongTask_Test
-    {
-        [TestMethod]
-        public void TestMethod()
-        {
-            int count = 0;
-            string errorMessage = "";
-
-            var task = new LongTask<object>
-            {                 
-                Processor = (worker) =>
-                {
-                    var _count = Interlocked.Increment(ref count);
-                    Thread.Sleep(100);
-                },
-                OnFinish = (status,_count) =>
-                {
-                    if (!
-                    (status == ETaskFinishStatus.success
-                    || (status == ETaskFinishStatus.overload && (int)_count > 100)
-                    ))
-                        errorMessage += Environment.NewLine + $"[{_count}]status : "+ status;
-                }
-            };
-
-            task.threadCount = 10;
-            task.pendingQueueLength = 100;      
-
-            task.Start();
-
-
-            for (var t = 0; t < 200; t++)
-                task.Publish(t);
-
-            Thread.Sleep(1050);
-            task.OnFinish = null;
-            task.Stop();
-
-            var curCount = count;
-            Assert.IsTrue(curCount <= 100);
-            Thread.Sleep(10);
-
-            Assert.IsTrue(!task.IsRunning);
-            var curCount2 = count;
-            Thread.Sleep(200);
-            Assert.AreEqual(count, curCount2);
-
-            if (!string.IsNullOrEmpty(errorMessage))
-                Assert.Fail(errorMessage);
-
-
-
-        }
-    }
-}

+ 12 - 13
dotnet/Library/Vit/Vit.Core/Test/Vit.Core.Util.Threading.Worker.MsTest/Worker/LongTask_TimeLimit_Test.cs → dotnet/Library/Vit/Vit.Core/Test/Vit.Core.Util.Threading.Worker.MsTest/Worker/ManagedThread_Test.cs

@@ -1,16 +1,12 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-
 using System;
 using System.Threading;
-using System.Threading.Tasks;
-using System.Timers;
-
 using Vit.Core.Util.Threading.Worker;
 
 namespace Vit.Core.Util.Threading.MsTest.Worker
 {
     [TestClass]
-    public class LongTask_TimeLimit_Test
+    public class ManagedThread_Test
     {
         [TestMethod]
         public void TestMethod()
@@ -18,7 +14,7 @@ namespace Vit.Core.Util.Threading.MsTest.Worker
             int count = 0;
             string errorMessage = "";
 
-            var task = new LongTask_TimeLimit<object>
+            var task = new ManagedThread<object>
             {                 
                 Processor = (worker) =>
                 {
@@ -27,15 +23,18 @@ namespace Vit.Core.Util.Threading.MsTest.Worker
                 },
                 OnFinish = (status,_count) =>
                 {
-                    if (!
-                    (status == ETaskFinishStatus.timeout
-                    || (status == ETaskFinishStatus.overload && (int)_count > 100)
-                    ))
+                    if( status == ETaskFinishStatus.timeout
+                       || (status == ETaskFinishStatus.overload && (int)_count > 100)
+                    ) 
+                        return;
+
                         errorMessage += Environment.NewLine + $"[{_count}]status : "+ status;
                 }
             };
 
-            task.threadCount = 10;
+            task.threadName = "TestThread";
+            task.threadCount = 4;
+            task.maxThreadCount = 10;
             task.pendingQueueLength = 100;
             task.timeoutMs = 100;
 
@@ -44,14 +43,14 @@ namespace Vit.Core.Util.Threading.MsTest.Worker
 
             for (var t = 0; t < 200; t++)
                 task.Publish(t);
-
+     
             Thread.Sleep(1050);
             task.OnFinish = null;
             task.Stop();
 
             var curCount = count;
             Assert.IsTrue(curCount <= 100);
-            Thread.Sleep(10);
+            Thread.Sleep(100);
 
             Assert.IsTrue(!task.IsRunning);
             var curCount2 = count;

+ 0 - 146
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/LongTask.cs

@@ -1,146 +0,0 @@
-using System;
-using System.Threading;
-using Vit.Core.Module.Log;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-using System.Collections.Concurrent;
-
-namespace Vit.Core.Util.Threading.Worker
-{
-    /// <summary>
-    /// 注意!!!慎用!!!
-    /// 线程数量限制不一定准确。
-    /// 请勿处理ThreadInterruptedException异常,否则导致线程无法正常结束
-    /// 若超时则强制关闭任务。
-    /// 通过Task.Run创建新线程。推任务的模式。
-    /// </summary>
-    public class LongTask<T> : IDisposable
-    {
-
-        /// <summary>
-        /// 不可抛异常
-        /// </summary>
-        public Action<T> Processor;
-
-        /// <summary>
-        /// 不可抛异常
-        /// status: success/error/overload
-        /// </summary>
-        public Action<ETaskFinishStatus, T> OnFinish;
-
-        /// <summary>
-        /// 线程数,默认16
-        /// </summary>
-        public int threadCount = 16;
-
-        /// <summary>
-        /// 等待队列的最大长度(默认:100000)
-        /// </summary>
-        public int pendingQueueLength = 100000;
-
-        int runningThreadCount = 0;
-
-        public int RunningThreadCount => runningThreadCount;
-
-
-        ConcurrentQueue<T> pendingQueue = new ConcurrentQueue<T>();
-
-        public bool IsRunning => NeedRunning;
-
-        bool NeedRunning { get; set; } = false;
-
-        ~LongTask()
-        {
-            Dispose();
-        }
-
-        public virtual void Dispose()
-        {
-            Stop();
-        }
-
-
-        public void Start()
-        {
-            NeedRunning = true;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <returns></returns>
-        public void Stop()
-        {
-            NeedRunning = false;
-            pendingQueue = new ConcurrentQueue<T>();
-        }
-
-
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public void Publish(T arg)
-        {
-            if (!IsRunning)
-            {
-                //(x.1)返回服务过载回应
-                OnFinish?.Invoke(ETaskFinishStatus.overload, arg);
-            }
-
-            //(x.2)启动新线程
-            if (runningThreadCount < threadCount)
-            {
-                StartNewTask(arg);
-                return;
-            }
-
-            //(x.3)推入等待队列
-            if (pendingQueue.Count < pendingQueueLength)
-            {
-                pendingQueue.Enqueue(arg);
-                return;
-            }
-        }
-
-
-
-
-
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        void StartNewTask(T arg_)
-        {
-            Task.Run(() =>
-            {
-                Interlocked.Increment(ref runningThreadCount);
-                T arg = arg_;
-                try
-                {
-                    while (NeedRunning)
-                    {
-                        #region (x.1) do work
-
-                        ETaskFinishStatus status = ETaskFinishStatus.success;
-                        try
-                        {
-                            Processor(arg);
-                        }
-                        catch (Exception ex)
-                        {
-                            status = ETaskFinishStatus.error;
-                            Logger.Error(ex);
-                        }
-                        finally
-                        {
-                            OnFinish?.Invoke(status, arg);
-                        }
-                        #endregion
-
-                        if (!pendingQueue.TryDequeue(out arg)) return;
-                    }
-                }
-                finally
-                {
-                    Interlocked.Decrement(ref runningThreadCount);
-                }
-            });
-        }
-    }
-}

+ 0 - 333
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/LongTask_TimeLimit.cs

@@ -1,333 +0,0 @@
-using System;
-using System.Threading;
-using Vit.Extensions;
-using Vit.Core.Module.Log;
-using Vit.Core.Util.Threading.Timer;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-using System.Collections.Concurrent;
-
-namespace Vit.Core.Util.Threading.Worker
-{
-    /// <summary>
-    /// 注意!!!慎用!!!
-    /// 线程数量限制不一定准确。
-    /// 请勿处理ThreadInterruptedException异常,否则导致线程无法正常结束
-    /// 若超时则强制关闭任务。
-    /// 通过Task.Run创建新线程。推任务的模式。
-    /// </summary>
-    public class LongTask_TimeLimit<T> : IDisposable
-    {
-
-        /// <summary>
-        /// 不可抛异常
-        /// </summary>
-        public Action<T> Processor;
-
-        /// <summary>
-        /// 不可抛异常
-        /// status: success/error/timeout/overload
-        /// </summary>
-        public Action<ETaskFinishStatus, T> OnFinish;
-
-        /// <summary>
-        /// 线程名称
-        /// </summary>
-        public string threadName;
-
-        /// <summary>
-        /// 线程数,默认100
-        /// </summary>
-        public int threadCount = 100;
-
-        /// <summary>
-        /// 等待队列的最大长度(默认:100000)
-        /// </summary>
-        public int pendingQueueLength = 100000;
-
-      
-        public int RunningThreadCount => runInfo.runningThreadCount;
-
-
-        #region RunInfo
-     
-        class RunInfo 
-        {
-          
-            /// <summary>
-            /// 运行中或准备启动的线程个数
-            /// </summary>
-            public int curThreadCount = 0;
-
-            /// <summary>
-            /// 在运行中的线程个数
-            /// </summary>
-            public int runningThreadCount = 0;
-
-            public readonly ConcurrentQueue<T> pendingQueue = new ConcurrentQueue<T>();
-
-            public readonly ConcurrentDictionary<int, WorkInfo> workInfoCache = new ConcurrentDictionary<int, WorkInfo>();
-
-        }
-        RunInfo runInfo = new RunInfo();
-
-        #endregion
-
-
-        public bool IsRunning => NeedRunning;
-
-        bool NeedRunning { get; set; } = false; 
-
-        /// <summary>
-        /// 超时时间。脉冲间隔。(主动关闭超过此时间的任务,实际任务强制关闭的时间会在1倍超时时间到2倍超时时间内)。单位:ms。(默认300000)
-        /// </summary>
-        public int timeoutMs { get => pulseMaker.intervalMs; set => pulseMaker.intervalMs = value; }
-
-
-        public LongTask_TimeLimit()
-        {
-            pulseMaker = new SersTimer { intervalMs = 300000, timerCallback = PulseMake };
-        }
-
-
-        ~LongTask_TimeLimit()
-        {
-            Dispose();
-        }
-
-        public virtual void Dispose()
-        {
-            Stop();
-        }
-
-
-        #region 电子脉冲
-        /// <summary>
-        /// 脉冲生产器
-        /// </summary>
-        readonly SersTimer pulseMaker;
-
-        /// <summary>
-        /// 电子脉冲,在固定的时间间隔发送脉冲
-        /// </summary>
-        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
-        public void PulseMake(object obj)
-        {
-            if (!IsRunning) return;
-
-            foreach (var workInfo in runInfo.workInfoCache.Values)
-            {
-                workInfo.Pulse();
-            }
-        }
-        #endregion
-
-
-        public void Start()
-        {
-            lock (this)
-            {
-                if (IsRunning)
-                {
-                    throw WorkerHelp.Error_CannotStartWhileRunning.ToException();
-                }
-                NeedRunning = true;              
-
-                //(x.2)开启脉冲生产器
-                pulseMaker.Start();
-            }
-        }
-
-        public void Stop()
-        {
-            lock (this)
-            {
-                if (!IsRunning) return;
-                NeedRunning = false;
-
-                try
-                {
-                    pulseMaker.Stop();
-                }
-                catch (Exception ex)
-                {
-                    Logger.Error(ex);
-                }
-
-                var info = runInfo;
-                runInfo = new RunInfo();
-                Task.Run(() =>
-                { 
-                    foreach (var workInfo in info.workInfoCache.Values)
-                    {
-                        workInfo.TryStop();
-                    }
-
-                    if (OnFinish != null) 
-                    {
-                        T arg;
-                        while (info.pendingQueue.TryDequeue(out arg))
-                        {
-                            OnFinish?.Invoke(ETaskFinishStatus.overload, arg);
-                        }
-                    }
-                });
-            }
-        }
-
-
-
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public void Publish(T arg)
-        {
-            if (IsRunning)
-            {
-                //(x.1)启动新线程
-                if (runInfo.runningThreadCount < threadCount)
-                {
-                    if(WorkInfo.StartNewTask(this, arg))
-                        return;
-                }
-
-                //(x.2)推入等待队列
-                if (runInfo.pendingQueue.Count < pendingQueueLength)
-                {
-                    runInfo.pendingQueue.Enqueue(arg);
-                    return;
-                }
-            }
-
-            //(x.3)返回服务过载回应
-            OnFinish?.Invoke(ETaskFinishStatus.overload, arg);
-        }
-
-       
-
-        class WorkInfo
-        {
-            int pulseCount = 0;
-
-            public T arg;
-            LongTask_TimeLimit<T> task;
-            public Thread thread;
-
-            [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            public bool TryStop()
-            {
-                try
-                {
-                    if (thread.IsAlive)
-                        thread.Interrupt();
-                }
-                catch { }
-                return thread.IsAlive;
-            }
-
-            [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            public void Pulse()
-            {
-                if (!thread.IsAlive)
-                    return;
-                try
-                {
-                    Interlocked.Increment(ref pulseCount);
-                    if (pulseCount >= 2)
-                        TryStop();
-                }
-                catch { }
-            }
-
-            [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            public static bool StartNewTask(LongTask_TimeLimit<T> task, T arg)
-            {
-                var info = task.runInfo;
-                var curThreadCount = Interlocked.Increment(ref info.curThreadCount);
-
-                try
-                {
-                    if (curThreadCount <= task.threadCount)
-                    {
-                        var workInfo = new WorkInfo { arg = arg, task = task };
-                        var thread = new Thread(workInfo.Run);
-                        workInfo.thread = thread;
-                        thread.IsBackground = true;
-                        thread.Name = task.threadName + "-" + thread.ManagedThreadId;
-                        thread.Start();
-                        return true;
-                    }                    
-                }
-                catch
-                {
-                    Interlocked.Decrement(ref info.curThreadCount);
-                    throw;
-                }
-
-                Interlocked.Decrement(ref info.curThreadCount);
-                return false;
-            }
-
-            [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            void Run()
-            {
-                var info = task.runInfo;
-                Interlocked.Increment(ref info.runningThreadCount);
-                try
-                {
-                    info.workInfoCache.TryAdd(this.GetHashCode(), this);
-
-                    T arg_;
-                    while (task.NeedRunning)
-                    {
-                        try
-                        {
-                            pulseCount = 0;
-                            if (arg == null)
-                            {
-                                if (!info.pendingQueue.TryDequeue(out arg_))
-                                    return;
-                            }
-                            else
-                            {
-                                arg_ = arg;
-                                arg = default;
-                            }
-
-                            #region do work
-                            ETaskFinishStatus status = ETaskFinishStatus.success;
-                            try
-                            {
-                                task.Processor(arg_);
-                            }
-                            catch (Exception ex) when (ex.GetBaseException() is ThreadInterruptedException)
-                            {
-                                status = ETaskFinishStatus.timeout;
-                            }
-                            catch (Exception ex)
-                            {
-                                status = ETaskFinishStatus.error;
-                                Logger.Error(ex);
-                            }
-                            finally
-                            {
-                                task.OnFinish?.Invoke(status, arg_);
-                            }
-                            #endregion
-                        }
-                        catch (Exception ex)
-                        {
-                            Logger.Error(ex);
-                        }
-                    }
-                }
-                finally
-                {
-                    Interlocked.Decrement(ref info.runningThreadCount);
-                    Interlocked.Decrement(ref info.curThreadCount);
-                    info.workInfoCache.TryRemove(this.GetHashCode(), out _);
-                }
-
-            }
-        }
-
-    }
-}

+ 2 - 1
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/LongThread_TimeLimit.cs

@@ -254,7 +254,7 @@ namespace Vit.Core.Util.Threading.Worker
                     {
                         try
                         {
-                            ETaskFinishStatus status = ETaskFinishStatus.success;
+                            ETaskFinishStatus status = ETaskFinishStatus.error;
                             try
                             {
                                 IsDealing = false;
@@ -268,6 +268,7 @@ namespace Vit.Core.Util.Threading.Worker
 
                                 //(x.x.3)
                                 Processor(workArg);
+                                status = ETaskFinishStatus.success;
                                 IsDealing = false;
                             }
                             catch (Exception ex) when (ex.GetBaseException() is ThreadInterruptedException)

+ 572 - 0
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/Threading/Worker/ManagedThread.cs

@@ -0,0 +1,572 @@
+using System;
+using System.Threading;
+using Vit.Extensions;
+using Vit.Core.Module.Log;
+using Vit.Core.Util.Threading.Timer;
+using System.Runtime.CompilerServices;
+using System.Collections.Concurrent;
+
+namespace Vit.Core.Util.Threading.Worker
+{
+    /// <summary>
+    /// 注意!!!慎用!!!
+    /// 线程数量限制不一定准确。
+    /// 请勿处理ThreadInterruptedException异常,否则导致线程无法正常结束
+    /// 若超时则强制关闭任务。
+    /// 托管线程。推任务的模式。
+    /// </summary>
+    public class ManagedThread<T> : IDisposable
+    {
+
+        /// <summary>
+        /// 不可抛异常
+        /// </summary>
+        public Action<T> Processor;
+
+        /// <summary>
+        /// 不可抛异常
+        /// status: success/error/timeout/overload
+        /// </summary>
+        public Action<ETaskFinishStatus, T> OnFinish;
+
+        /// <summary>
+        /// 线程名称
+        /// </summary>
+        public string threadName;
+
+        /// <summary>
+        /// 常驻线程数,默认16。可为0
+        /// </summary>
+        public int threadCount = 16;
+
+        /// <summary>
+        /// 最大线程数(包含常驻线程和临时线程),默认100。
+        /// </summary>
+        public int maxThreadCount = 100;
+
+        /// <summary>
+        /// 等待队列的最大长度(默认:100000)
+        /// </summary>
+        public int pendingQueueLength = 100000;
+
+
+        public bool IsRunning => runInfo != null;
+
+
+        /// <summary>
+        /// 超时时间。脉冲间隔。(主动关闭超过此时间的任务,实际任务强制关闭的时间会在1倍超时时间到2倍超时时间内)。单位:ms。(默认300000)
+        /// </summary>
+        public int timeoutMs { get => pulseMaker.intervalMs; set => pulseMaker.intervalMs = value; }
+
+
+        public ManagedThread()
+        {
+            pulseMaker = new SersTimer { intervalMs = 300000, timerCallback = Pulse };
+        }
+
+
+        ~ManagedThread()
+        {
+            Dispose();
+        }
+
+        public virtual void Dispose()
+        {
+            Stop();
+        }
+
+
+        #region 电子脉冲
+        /// <summary>
+        /// 脉冲生产器
+        /// </summary>
+        readonly SersTimer pulseMaker;
+
+        /// <summary>
+        /// 电子脉冲,在固定的时间间隔发送脉冲
+        /// </summary>
+        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
+        public void Pulse(object obj)
+        {
+            runInfo?.Pulse();
+        }
+        #endregion
+
+
+        public void Start()
+        {
+            lock (this)
+            {
+                if (IsRunning)
+                {
+                    throw WorkerHelp.Error_CannotStartWhileRunning.ToException();
+                }
+
+                //(x.1)
+                runInfo = new RunInfo(this);
+                runInfo.Start();
+
+                //(x.2)开启脉冲生产器
+                pulseMaker.Start();
+            }
+        }
+
+        public void Stop()
+        {
+            lock (this)
+            {
+                if (!IsRunning) return;
+
+                runInfo.needRunning = false;
+
+                var info = runInfo;
+                runInfo = null;
+
+                //关闭脉冲生产器
+                try
+                {
+                    pulseMaker.Stop();
+                }
+                catch (Exception ex)
+                {
+                    Logger.Error(ex);
+                }
+
+                //Task.Run(() =>
+                {
+                    //(x.1)终止常驻线程
+                    foreach (var thread in info.longThreadManager.threads)
+                    {
+                        try
+                        {
+                            thread.Pulse();
+                            thread.Pulse();
+                        }
+                        catch (Exception)
+                        {
+                        }
+                    }
+
+                    //(x.2)终止临时线程
+                    foreach (var thread in info.casualThreadManager.threadMap.Values)
+                    {
+                        try
+                        {
+                            thread.Pulse();
+                            thread.Pulse();
+                        }
+                        catch (Exception)
+                        {
+                        }
+                    }
+
+                    //(x.3)清空等待队列
+                    if (OnFinish != null)
+                    {
+                        T arg;
+                        while (info.pendingQueue.TryTake(out arg))
+                        {
+                            OnFinish?.Invoke(ETaskFinishStatus.overload, arg);
+                        }
+                    }
+                }
+                //);
+            }
+        }
+
+
+
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        public void Publish(T arg)
+        {
+            if (IsRunning)
+            {
+                //(x.1)启动临时线程
+                if (runInfo.longThreadManager.waitingThreadCount == 0
+                    && runInfo.casualThreadManager.TryStartNewThread(arg))
+                {
+                    return;
+                }
+
+                //(x.2)推入等待队列
+                if (runInfo.pendingQueue.TryAdd(arg))
+                {
+                    return;
+                }
+            }
+
+            //(x.3)返回服务过载回应
+            OnFinish?.Invoke(ETaskFinishStatus.overload, arg);
+        }
+
+
+        #region RunInfo
+
+        class RunInfo
+        {
+            /// <summary>
+            /// 不可抛异常
+            /// </summary>
+            public Action<T> Processor;
+
+            /// <summary>
+            /// 不可抛异常
+            /// status: success/error/timeout/overload
+            /// </summary>
+            public Action<ETaskFinishStatus, T> OnFinish;
+
+
+            public bool needRunning = true;
+
+            public readonly BlockingCollection<T> pendingQueue;
+
+            public LongThreadManager longThreadManager;
+
+            public CasualThreadManager casualThreadManager;
+
+ 
+            public RunInfo(ManagedThread<T> task)
+            {   
+
+                this.Processor = task.Processor;
+                this.OnFinish = task.OnFinish;
+
+
+                pendingQueue = new BlockingCollection<T>(task.pendingQueueLength);
+
+
+                longThreadManager = new LongThreadManager(task);
+
+                casualThreadManager = new CasualThreadManager(task);
+            }
+
+
+            public void Start() 
+            {
+                longThreadManager.Start();
+            }
+
+
+            /// <summary>
+            /// 电子脉冲,在固定的时间间隔发送脉冲
+            /// </summary>
+            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
+            public void Pulse()
+            {
+                longThreadManager.Pulse();
+                casualThreadManager.Pulse();
+            }
+
+        }
+        #endregion
+
+
+        RunInfo runInfo;
+
+
+
+
+
+        #region Manager 
+        class LongThreadManager
+        {
+            /// <summary>
+            /// 等待中的线程个数
+            /// </summary>
+            public int waitingThreadCount = 0;
+
+            public LongThread[] threads;
+            ManagedThread<T> task;
+            public LongThreadManager(ManagedThread<T> task)
+            {
+                this.task = task;
+            }
+
+            public void Start()
+            {
+                threads = new LongThread[task.threadCount];
+                for (int i = 0; i < threads.Length; i++)
+                {
+                    threads[i] = new LongThread(task,i);
+                }
+            }
+
+            /// <summary>
+            /// 电子脉冲,在固定的时间间隔发送脉冲
+            /// </summary>
+            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
+            public void Pulse()
+            {
+                foreach (var thread in threads)
+                {
+                    thread?.Pulse();
+                }
+            }
+        }
+        class CasualThreadManager
+        {
+            public readonly ConcurrentDictionary<int, CasualThread> threadMap = new ConcurrentDictionary<int, CasualThread>();
+
+            ManagedThread<T> task;
+
+            public int runningThreadCount = 0;
+
+            public int curThreadCount = 0;
+
+            int maxThreadCount;
+            public CasualThreadManager(ManagedThread<T> task)
+            {
+                this.task = task;
+                maxThreadCount = task.maxThreadCount - task.threadCount;
+            }
+
+
+            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
+            public bool TryStartNewThread(T arg)
+            {
+                var curThreadCount = Interlocked.Increment(ref this.curThreadCount);
+                try
+                {
+                    if (curThreadCount <= maxThreadCount)
+                    {
+                        new CasualThread(task, arg);
+                        return true;
+                    }
+                }
+                catch
+                {
+                    Interlocked.Decrement(ref this.curThreadCount);
+                    throw;
+                }
+
+                Interlocked.Decrement(ref this.curThreadCount);
+                return false; 
+            }
+
+
+            /// <summary>
+            /// 电子脉冲,在固定的时间间隔发送脉冲
+            /// </summary>
+            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
+            public void Pulse()
+            {
+                foreach (var thread in threadMap.Values)
+                {
+                    thread?.Pulse();
+                }
+            }
+        }
+
+        #endregion
+
+        #region Thread
+
+
+
+
+        class LongThread
+        {
+            RunInfo runInfo;
+
+            LongThreadManager manager;
+
+            bool isProcessing = false;
+
+            int pulseCount = 0;
+
+            Thread thread;
+
+
+            public LongThread(ManagedThread<T> task,int index)
+            {
+                this.runInfo = task.runInfo;
+                this.manager = runInfo.longThreadManager;
+
+                thread = new Thread(Run);
+                thread.IsBackground = true;
+                thread.Name = task.threadName + "-LongThread-" + index + "-" + thread.ManagedThreadId;
+
+                thread.Start();
+            }
+
+
+
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            public void Pulse()
+            {
+                if (thread == null || !thread.IsAlive || !isProcessing)
+                    return;
+                try
+                {
+                    Interlocked.Increment(ref pulseCount);
+                    if (pulseCount >= 2)
+                        thread.Interrupt();
+                }
+                catch { }
+            }
+
+
+
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            void Run()
+            {
+                try
+                {
+                    T arg_;
+                    while (runInfo.needRunning)
+                    {
+                        try
+                        {
+                            isProcessing = false;
+                            Interlocked.Increment(ref manager.waitingThreadCount);
+                            arg_ = runInfo.pendingQueue.Take();
+                            Interlocked.Decrement(ref manager.waitingThreadCount);
+                            pulseCount = 0;
+                            isProcessing = true;
+
+                            #region processing 
+                            ETaskFinishStatus status = ETaskFinishStatus.error;
+                            try
+                            {
+                                runInfo.Processor(arg_);
+                                status = ETaskFinishStatus.success;
+                            }
+                            catch (Exception ex) when (ex.GetBaseException() is ThreadInterruptedException)
+                            {
+                                status = ETaskFinishStatus.timeout;
+                            }
+                            catch (Exception ex)
+                            {
+                                status = ETaskFinishStatus.error;
+                                Logger.Error(ex);
+                            }
+                            finally
+                            {
+                                runInfo.OnFinish?.Invoke(status, arg_);
+                            }
+                            #endregion
+                        }
+                        catch (Exception ex)
+                        {
+                            Logger.Error(ex);
+                        }
+                    }
+                }
+                finally
+                {
+                    thread = null;
+                }
+            }
+        }
+
+        class CasualThread
+        {
+            RunInfo runInfo;
+
+            int pulseCount = 0;
+
+            T arg;
+            Thread thread;
+
+            CasualThreadManager manager;
+
+
+            [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
+            public CasualThread(ManagedThread<T> task, T arg)
+            {
+                this.runInfo = task.runInfo;
+                this.manager = runInfo.casualThreadManager;
+                this.arg = arg;
+
+                thread = new Thread(Run);
+                thread.IsBackground = true;
+                thread.Name = task.threadName + "-Casual-" + thread.ManagedThreadId;
+                thread.Start();
+            }
+
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            public void Pulse()
+            {
+                if (!thread.IsAlive)
+                {
+                    manager.threadMap.TryRemove(this.GetHashCode(), out _);
+                    return;
+                }
+
+                try
+                {
+                    Interlocked.Increment(ref pulseCount);
+                    if (pulseCount >= 2)
+                        thread.Interrupt();
+                }
+                catch { }
+            }
+
+
+
+            [MethodImpl(MethodImplOptions.AggressiveInlining)]
+            void Run()
+            {
+                Interlocked.Increment(ref manager.runningThreadCount);
+                try
+                {
+                    manager.threadMap.TryAdd(this.GetHashCode(), this);
+
+                    T arg_;
+                    while (runInfo.needRunning)
+                    {
+                        try
+                        {
+                            pulseCount = 0;
+                            if (arg == null)
+                            {
+                                if (!runInfo.pendingQueue.TryTake(out arg_))
+                                    return;
+                            }
+                            else
+                            {
+                                arg_ = arg;
+                                arg = default;
+                            }
+
+                            #region processing
+                            ETaskFinishStatus status = ETaskFinishStatus.error;
+                            try
+                            {
+                                runInfo.Processor(arg_);
+                                status = ETaskFinishStatus.success;
+                            }
+                            catch (Exception ex) when (ex.GetBaseException() is ThreadInterruptedException)
+                            {
+                                status = ETaskFinishStatus.timeout;
+                            }
+                            catch (Exception ex)
+                            {
+                                status = ETaskFinishStatus.error;
+                                Logger.Error(ex);
+                            }
+                            finally
+                            {
+                                runInfo.OnFinish?.Invoke(status, arg_);
+                            }
+                            #endregion
+                        }
+                        catch (Exception ex)
+                        {
+                            Logger.Error(ex);
+                        }
+                    }
+                }
+                finally
+                {
+                    Interlocked.Decrement(ref manager.runningThreadCount);
+                    manager.threadMap.TryRemove(this.GetHashCode(), out _);
+                }
+
+            }
+        }
+
+
+        #endregion
+    }
+}

+ 1 - 1
dotnet/Library/Vit/Vit.Core/Vit.Core/Vit.Core.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.9</Version>
+		<Version>2.1.10-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Vit/Vit.Net.Http.FormFile/Vit.Net.Http.FormFile.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.9</Version>
+		<Version>2.1.10-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/Library/Vit/Vit.WebHost/Vit.WebHost.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.9</Version>
+		<Version>2.1.10-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/ServiceCenter/App.Gover.Gateway/App.Gover.Gateway.csproj

@@ -8,7 +8,7 @@
 	<PropertyGroup>
 		<OutputType>Exe</OutputType>
 		<TargetFramework>netcoreapp2.1</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 		<PackageProjectUrl>https://github.com/serset/Sers</PackageProjectUrl>
 	</PropertyGroup>
 

+ 8 - 8
dotnet/ServiceCenter/App.ServiceCenter.NetFx/App.ServiceCenter.NetFx/packages.config

@@ -4,14 +4,14 @@
   <package id="Microsoft.DotNet.PlatformAbstractions" version="2.0.0" targetFramework="net461" />
   <package id="Microsoft.Extensions.DependencyModel" version="2.0.0" targetFramework="net461" />
   <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
-  <package id="Sers.CL.Ipc.NamedPipe" version="2.1.10" targetFramework="net461" />
-  <package id="Sers.CL.Socket.Iocp" version="2.1.10" targetFramework="net461" />
-  <package id="Sers.CL.Socket.ThreadWait" version="2.1.10" targetFramework="net461" />
-  <package id="Sers.CL.WebSocket" version="2.1.10" targetFramework="net461" />
-  <package id="Sers.Core" version="2.1.10" targetFramework="net461" />
-  <package id="Sers.Gover" version="2.1.10" targetFramework="net461" />
-  <package id="Sers.Hardware" version="2.1.10" targetFramework="net461" />
-  <package id="Sers.ServiceCenter" version="2.1.10" targetFramework="net461" />
+  <package id="Sers.CL.Ipc.NamedPipe" version="2.1.11-temp" targetFramework="net461" />
+  <package id="Sers.CL.Socket.Iocp" version="2.1.11-temp" targetFramework="net461" />
+  <package id="Sers.CL.Socket.ThreadWait" version="2.1.11-temp" targetFramework="net461" />
+  <package id="Sers.CL.WebSocket" version="2.1.11-temp" targetFramework="net461" />
+  <package id="Sers.Core" version="2.1.11-temp" targetFramework="net461" />
+  <package id="Sers.Gover" version="2.1.11-temp" targetFramework="net461" />
+  <package id="Sers.Hardware" version="2.1.11-temp" targetFramework="net461" />
+  <package id="Sers.ServiceCenter" version="2.1.11-temp" targetFramework="net461" />
   <package id="System.Buffers" version="4.5.1" targetFramework="net461" />
   <package id="Vit.Core" version="2.1.9" targetFramework="net461" />
 </packages>

+ 1 - 1
dotnet/ServiceCenter/App.ServiceCenter/App.ServiceCenter.csproj

@@ -8,7 +8,7 @@
 	<PropertyGroup>
 		<OutputType>Exe</OutputType>
 		<TargetFramework>netcoreapp2.1</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 		<PackageProjectUrl>https://github.com/serset/Sers</PackageProjectUrl>
 	</PropertyGroup>
 

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Apm/Sers.Gover.Apm.Txt/Sers.Gover.Apm.Txt.csproj

@@ -2,7 +2,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Apm/Sers.Gover.Apm.Zipkin/Sers.Gover.Apm.Zipkin.csproj

@@ -2,7 +2,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.Gover/Sers.Gover.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter/Sers.ServiceCenter.csproj

@@ -6,7 +6,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>netstandard2.0</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 	</PropertyGroup>
 
 	<PropertyGroup>

+ 1 - 1
dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.Demo/Did.SersLoader.Demo.csproj

@@ -8,7 +8,7 @@
   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp2.1</TargetFramework>
-    <Version>2.1.10</Version>
+    <Version>2.1.11-temp</Version>
     <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
     <Description>https://github.com/serset/Sers</Description>
   </PropertyGroup>

+ 23 - 0
dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.Demo/Program.cs

@@ -1,6 +1,8 @@
 using Sers.SersLoader;
 using Sers.ServiceStation;
 
+using System.Collections.Concurrent;
+
 namespace Did.SersLoader.Demo
 {
     public class Program
@@ -9,6 +11,27 @@ namespace Did.SersLoader.Demo
         public static void Main(string[] args)
         {
 
+
+            BlockingCollection<object> queue=new BlockingCollection<object>(10);
+            //queue.BoundedCapacity
+            try
+            {
+                for(var t=0;t<10;t++)
+                queue.Add(new object());
+
+                var td = queue.TryAdd(new object());
+
+                queue.Add(new object());
+
+
+            }
+            catch (System.Exception ex)
+            {
+
+                throw;
+            }
+
+
             //ServiceStation.AutoRun();
 
 

+ 1 - 1
dotnet/ServiceStation/Demo/SersLoader/Did.SersLoader.HelloWorld/Did.SersLoader.HelloWorld.csproj

@@ -3,7 +3,7 @@
 	<PropertyGroup>
 		<OutputType>Exe</OutputType>
 		<TargetFramework>netcoreapp2.1</TargetFramework>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 		<Description>https://github.com/serset/Sers</Description>
 	</PropertyGroup>
 

+ 1 - 1
dotnet/ServiceStation/Demo/StressTest/App.Robot.Station/App.Robot.Station.csproj

@@ -9,7 +9,7 @@
 		<OutputType>Exe</OutputType>
 		<TargetFramework>netcoreapp2.1</TargetFramework>
 		<RunPostBuildEvent>Always</RunPostBuildEvent>
-		<Version>2.1.10</Version>
+		<Version>2.1.11-temp</Version>
 		<Description>https://github.com/serset/Sers</Description>
 	</PropertyGroup>