Skip to content

Commit

Permalink
接收允许在一个线程中
Browse files Browse the repository at this point in the history
  • Loading branch information
walterlv committed Dec 15, 2021
1 parent c404dcb commit 4c388fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/dotnetCampus.Ipc/Properties/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
launchSettings.json
3 changes: 2 additions & 1 deletion src/dotnetCampus.Ipc/Threading/IpcSingleThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ internal class IpcSingleThreadPool : IIpcThreadPool
{
public async Task<Task> Run(Action action, ILogger? logger)
{
action();
// 因为此方法的调用方能保证依次执行而不并发,所以这里直接 Task.Run 也不会浪费线程。
await Task.Run(action).ConfigureAwait(false);
//await Task.Run(action).ConfigureAwait(false);
return Task.FromResult(0);
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/dotnetCampus.Ipc/Threading/IpcTaskScheduling.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
namespace dotnetCampus.Ipc.Threading
using System;

namespace dotnetCampus.Ipc.Threading
{
/// <summary>
/// 决定 IPC 消息抵达时,以何种调度方式通知给业务代码。
/// </summary>
public enum IpcTaskScheduling
{
/// <summary>
/// 所有的 IPC 共享同一个调度线程池。以大体上按顺序(但不保证)的并发方式通知。
/// </summary>
GlobalConcurrent,

/// <summary>
/// 按顺序依次通知。
/// </summary>
Expand All @@ -20,6 +17,12 @@ public enum IpcTaskScheduling
/// </list>
/// <para>在这种情况下,按顺序的发送方式将导致死锁。</para>
/// </remarks>
OneByOne,
[Obsolete("尚未开发完成。")]
Temp = -1,

/// <summary>
/// 所有的 IPC 共享同一个调度线程池。以大体上按顺序(但不保证)的并发方式通知。
/// </summary>
GlobalConcurrent = 0,
}
}
4 changes: 4 additions & 0 deletions src/dotnetCampus.Ipc/dotnetCampus.Ipc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Debug'">
<PackageReference Include="dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug" Version="1.3.217" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Walterlv.NullableAttributes.Source" Version="7.0.1" PrivateAssets="all" />
<PackageReference Include="dotnetCampus.AsyncWorkerCollection.Source" Version="1.6.5">
Expand Down

0 comments on commit 4c388fe

Please sign in to comment.