【发布时间】:2013-07-30 09:22:58
【问题描述】:
Windows 7 家庭高级版
视觉基础
有没有办法暂停程序的执行,但保持事件处理程序运行?
我的 Visual Basic 控制台应用程序监视文件事件,并使用熟悉的事件处理程序处理这些事件。
当前算法:
1. 创建 FileSystemWatcher
2. 设置事件处理程序
3. 等待用户的控制台输入,然后退出。
我可以用系统调用替换最后一步以暂停前台的执行,同时事件处理程序继续对事件做出反应吗?
这是代码的概要(删除了许多行)。
Dim watcher As New FileSystemWatcher() 'Create a new FileSystemWatcher
AddHandler watcher.Changed, AddressOf OnChanged 'Add event handler
watcher.EnableRaisingEvents = True 'Begin watching
'I wish to replace this with a system call to suspend
'execution, but keep the event handlers running.
While Chr(Console.Read()) <> "q"c 'Wait for the user to quit
End While
【问题讨论】:
-
我想你真正要找的是如何创建一个后台进程?