考虑一个Console应用程序,它在一个单独的线程中启动一些服务.它需要做的就是等待用户按Ctrl + C将其关闭.
以下哪项是更好的方法?
static ManualResetEvent _quitEvent = new ManualResetEvent(false);
static void Main() {
Console.CancelKeyPress += (sender, eArgs) => {
_quitEvent.Set();
eArgs.Cancel = true;
};
// kick off asynchronous stuff
_quitEvent.WaitOne();
// cleanup/shutdown and quit
}
Run Code Online (Sandbox Code Playgroud)
或者,使用Thread.Sleep(1):
static bool _quitFlag = false;
static void Main() {
Console.CancelKeyPress += delegate {
_quitFlag = true;
};
// kick off asynchronous stuff
while (!_quitFlag) {
Thread.Sleep(1);
}
// cleanup/shutdown and quit
}
Run Code Online (Sandbox Code Playgroud) 我有一个SearchController,其动作可以执行一些长时间运行的搜索并返回结果页面.搜索可能需要1到60秒.搜索的URL是以下格式的HTTP GET请求:http://localhost/Search?my=query&is=fancy
我正在寻找的体验类似于那里的许多旅游网站.我想展示一个中间的"正在加载......"页面,理想情况是:
这些都是不错的选择.我对所有想法持开放态度!谢谢.
c# asp.net-mvc performance user-interface progressive-enhancement