"暂停"执行,但保持事件处理程序运行?

时间:2013-07-30 00:55:50

标签: vb.net suspend

Windows 7 Home Premium
Visual Basic

有没有办法暂停执行程序,但保持事件处理程序运行?

我的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

1 个答案:

答案 0 :(得分:0)

您似乎正在尝试创建服务。要做到这一点,最简单的方法可能是基于“Windows服务”模板创建一个新项目并迁移现有代码。

MSDN文档:http://msdn.microsoft.com/en-us/library/d56de412.aspx