2013-07-30 142 views
0

Windows 7家庭高級版
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 
+0

我想你真正需要的是如何創建一個後臺進程? –

回答