我安装了一个带有FileSystemWatcher的Windows服务。它会扫描文件夹,每当在文件夹中创建新文件时,它都会调用Web浏览器。以下是代码。该服务工作正常,我可以在任务管理器的进程中看到浏览器(iexplorer.exe),但它不会出现在屏幕上。任何人都可以提出错误的建议吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
namespace InvokeBrowser
{
public partial class Service1 : ServiceBase
{
static FileSystemWatcher fsw;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
fsw = new FileSystemWatcher(@"path");
fsw.Created += new FileSystemEventHandler(fsw_Created);
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
fsw.EnableRaisingEvents = true;
}
void fsw_Changed(object sender, FileSystemEventArgs e)
{
try
{
string url = "http://www.google.com";
Process.Start(url);
}
catch (Exception)
{
throw;
}
}
void fsw_Created(object sender, FileSystemEventArgs e)
{
try
{
string url = "http://www.google.com";
Process.Start(url);
}
catch (Exception)
{
throw;
}
}
protected override void OnStop()
{
}
}
}
感谢。