Skip to content

Commit

Permalink
Merge pull request #19232 from abpframework/docfix
Browse files Browse the repository at this point in the history
Update Background-Workers document
  • Loading branch information
maliming authored Mar 7, 2024
2 parents ad9b702 + 76f8ff5 commit b7a11b4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/en/Background-Workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase
}
````

* `AsyncPeriodicBackgroundWorkerBase` uses the `AbpTimer` (a thread-safe timer) object to determine **the period**. We can set its `Period` property in the constructor.
* `AsyncPeriodicBackgroundWorkerBase` uses the `AbpAsyncTimer` (a thread-safe timer) object to determine **the period**. We can set its `Period` property in the constructor.
* It required to implement the `DoWorkAsync` method to **execute** the periodic work.
* It is a good practice to **resolve dependencies** from the `PeriodicBackgroundWorkerContext` instead of constructor injection. Because `AsyncPeriodicBackgroundWorkerBase` uses a `IServiceScope` that is **disposed** when your work finishes.
* `AsyncPeriodicBackgroundWorkerBase` **catches and logs exceptions** thrown by the `DoWorkAsync` method.
Expand Down
4 changes: 2 additions & 2 deletions docs/zh-Hans/Background-Workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MyWorker : BackgroundWorkerBase
public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase
{
public PassiveUserCheckerWorker(
AbpTimer timer,
AbpAsyncTimer timer,
IServiceScopeFactory serviceScopeFactory
) : base(
timer,
Expand All @@ -71,7 +71,7 @@ public class PassiveUserCheckerWorker : AsyncPeriodicBackgroundWorkerBase
}
````

* `AsyncPeriodicBackgroundWorkerBase` 使用 `AbpTimer`(线程安全定时器)对象来确定**时间段**. 我们可以在构造函数中设置了`Period` 属性.
* `AsyncPeriodicBackgroundWorkerBase` 使用 `AbpAsyncTimer`(线程安全定时器)对象来确定**时间段**. 我们可以在构造函数中设置了`Period` 属性.
* 它需要实现 `DoWorkAsync` 方法**执行**定期任务.
* 最好使用 `PeriodicBackgroundWorkerContext` **解析依赖** 而不是构造函数. 因为 `AsyncPeriodicBackgroundWorkerBase` 使用 `IServiceScope` 在你的任务执行结束时会对其 **disposed**.
* `AsyncPeriodicBackgroundWorkerBase` **捕获并记录**`DoWorkAsync` 方法抛出的 **异常**.
Expand Down

0 comments on commit b7a11b4

Please sign in to comment.