无法注册后台任务

Cannot register a background task

我正在编写一个应用程序,持续扫描范围内的所有接入点并将日志保存到文本文件中。当用户单击 "Start" 按钮和 运行 时应该开始扫描,直到单击 "Stop" 按钮,即使用户切换到其他应用程序也是如此。

据我所知,可以使用后台任务实现此功能,但在尝试注册后台任务时,我一直收到异常提示 "Not enough quota is available to process this command. (Exception from HRESULT: 0x80070718)"。

任何想法,可能有什么问题?

完整代码: https://www.dropbox.com/sh/1v9mbr3xhgr3283/AACDbB7skZUI7Z5fiu0HT8r4a?dl=0

您是否在每次应用 运行 时都注册后台任务?您是否正在检查它是否已经注册?可以多次注册您的后台任务,并且由于只允许注册这么多后台任务(取决于设备),因此您可能 运行 容量不足。检查 this page,其中提供了以下引用:

It's important to check this because if a task is registered multiple times, it will run more than once whenever it’s triggered; this can use excess CPU and may cause unexpected behavior.