Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Bug】请支持 Ctrl+C 退出 #344

Closed
seiuneko opened this issue Dec 1, 2022 · 4 comments
Closed

【Bug】请支持 Ctrl+C 退出 #344

seiuneko opened this issue Dec 1, 2022 · 4 comments
Labels
done done enhancement New feature or request

Comments

@seiuneko
Copy link
Contributor

seiuneko commented Dec 1, 2022

版本号:0.2.3.r7.gcc45c4f
运行环境:Arch Linux
问题描述:在 Linux 执行时按 Ctrl+C 无法退出程序。

@RayWangQvQ RayWangQvQ added the enhancement New feature or request label Dec 10, 2022
@RayWangQvQ
Copy link
Owner

OK

@RayWangQvQ RayWangQvQ pinned this issue Feb 13, 2023
@RayWangQvQ
Copy link
Owner

学习了一波,原因是dotnet启动过程是,先构建host,然后遍历已注册的所有HostedService,挨个执行StartAsync,全部执行结束后,被视为启动成功。在这之后,Console会监控Ctrl+C事件,触发后会终止应用(HostApplication)。

当前bilibili_tool是利用一个BiliHostedService,在它StartAsync里跑任务,也就是跑完任务才算启动结束(也是bili任务的终止),所以在跑任务过程中没法Ctrl+C退出。

解决方案的话,我想到2个:

  1. 在启动过程中自己想办法监控Ctrl+C事件(但设计上有点冗余和丑陋)
  2. 想办法把执行任务的逻辑从HostedService分离出去,让应用先启动完成,然后在去执行任务(比如把任务交给Hangfire或Quartz去触发)

@RayWangQvQ
Copy link
Owner

RayWangQvQ commented Feb 18, 2023

打脸了,其实是一直在监控着Ctrl+C的(由ConsoleLifetime),没触发是因为没有传递CancellationToken

下个版本我来修复

@RayWangQvQ RayWangQvQ added the done done label Feb 23, 2023
@RayWangQvQ RayWangQvQ unpinned this issue Feb 23, 2023
@RayWangQvQ
Copy link
Owner

已于v1.0.0发布支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done done enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants