Skip to content

Commit

Permalink
v1.0.7 修复 RemoveTempTask 无效的 bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Aug 31, 2022
1 parent 17a2c1e commit 3c67bd7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
29 changes: 28 additions & 1 deletion Examples/Examples_FreeScheduler_WinformNet40/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Examples/Examples_FreeScheduler_WinformNet40/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,27 @@ private void button5_Click(object sender, EventArgs e)
{
_scheduler.AddTask($"test_-1_task_{DateTime.Now.ToString("g")}", $"test_-1_body{DateTime.Now.ToString("g")}", -1, 5);
}

string tempTaskId = "";
private void button6_Click(object sender, EventArgs e)
{
button6.Enabled = false;
tempTaskId = _scheduler.AddTempTask(TimeSpan.FromSeconds(5), callback);
button7.Enabled = true;

void callback()
{
Console.WriteLine($"[{DateTime.Now.ToString("G")}] {tempTaskId} 到时触发");
tempTaskId = _scheduler.AddTempTask(TimeSpan.FromSeconds(5), callback);
}
}

private void button7_Click(object sender, EventArgs e)
{
button7.Enabled = false;
MessageBox.Show(_scheduler.RemoveTempTask(tempTaskId).ToString());
tempTaskId = "";
button6.Enabled = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
<Version>1.0.6</Version>
<Version>1.0.7</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
<Description>轻量化定时任务调度,支持临时的延时任务和重复循环任务,可按秒,每天/每周/每月固定时间,自定义间隔执行,支持 .NET Core 2.1+、.NET Framework 4.0+ 运行环境。</Description>
Expand Down
2 changes: 1 addition & 1 deletion FreeScheduler/FreeScheduler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
<Version>1.0.6</Version>
<Version>1.0.7</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
<Description>轻量化定时任务调度,支持临时的延时任务和重复循环任务,可按秒,每天/每周/每月固定时间,自定义间隔执行,支持 .NET Core 2.1+、.NET Framework 4.0+ 运行环境。</Description>
Expand Down
6 changes: 4 additions & 2 deletions FreeScheduler/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public string AddTempTask(TimeSpan timeout, Action handle)
var bus = new IdleTimeout(() =>
{
if (isdisposed) return;
_ib.TryRemove(id);
if (_ib.TryRemove(id) == false) return;
Interlocked.Decrement(ref _quantityTempTask);
if (handle != null)
_wq.Enqueue(handle);
Expand All @@ -104,7 +104,9 @@ public string AddTempTask(TimeSpan timeout, Action handle)
public bool RemoveTempTask(string id)
{
if (_tasks.ContainsKey(id)) return false;
return _ib.TryRemove(id);
if (_ib.TryRemove(id) == false) return false;
Interlocked.Decrement(ref _quantityTempTask);
return true;
}
/// <summary>
/// 判断临时任务是否存在
Expand Down

0 comments on commit 3c67bd7

Please sign in to comment.