【问题标题】:"Suspend" execution, but keep event handlers running?“暂停”执行,但保持事件处理程序运行?
【发布时间】: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

【问题讨论】:

  • 我想你真正要找的是如何创建一个后台进程?

标签: vb.net suspend


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2016-03-21
    • 2012-02-20
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    • 2020-02-15
    • 2015-01-02
    • 1970-01-01
    • 2011-10-27
    相关资源
    最近更新 更多