c。与filewatcher#窗口服务
第一次发布很长一段时间的读者。c。与filewatcher#窗口服务
我建了一个将它移动到窗口服务之前正确filewatcher Windows窗体应用程序运行100%的容器内工作,我现在recieving两个单独的问题。此文件观察器读取行更新(lastwrite)的平面文件,删除/重新创建文件(streamwriter),最后解析强类型数据集,然后上载到SQL服务器。 (这是我的第一个Windows服务) 问题:
1.该双事件触发的filewatcher效果服务不同则表单应用程序?
2.有没有人有答案,为什么线程会打破,如果我打电话的课程没有问题?
3.通过Windows服务进行Windows身份验证是否存在任何已知问题?
4.有没有人有强大的Windows服务调试方法?
下面是Windows服务,在此先感谢和我的道歉我的代码,如果代码中的一个愚蠢的错误,又第一次拍Windows服务。
FileMonitor m_FileMonitor;
public WindowsService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
Thread myThread = new Thread(DoTheWork);
myThread.Start();
}
catch
{
}
}
void DoTheWork()
{
m_FileMonitor = new FileMonitor(Properties.Settings.Default.PathToFileToWatch, Properties.Settings.Default.PathToErrorLog);
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
}
为了调试:
您必须使用ServiceBase.Run
方法Main()
执行作为Windows服务,但你可以在main方法的交换机,来运行相同的应用程序作为一个正常的控制台应用程序(例如--standalone
)。我在我的所有服务中都使用它来使它们易于调试。
至于其他问题:
我不能完全肯定你会遇到哪些问题,你的“课间”和“双事件触发”的意思。
的Windows服务在一个特殊的服务帐户运行,这可能会或可能没有权限看你感兴趣的目录,你可以更改服务帐户或给它权限的目录,如果你需要。
链接:
这里是一个CodeProject上的文章谁似乎已经实现了一个文件观察者窗口服务的链接。也许它可以帮助:
http://www.codeproject.com/Articles/18521/How-to-implement-a-simple-filewatcher-Windows-serv
要进行调试,请确保您的项目类型是Windows应用程序,然后使用该命令:
[DllImport("kernel32")]
static extern bool AllocConsole();
private static void Main(string[] args)
{
var service = new MyService();
var controller = ServiceController.GetServices().FirstOrDefault(c => c.ServiceName == service.ServiceName);
if (null != controller && controller.Status == ServiceControllerStatus.StartPending)
{
ServiceBase.Run(service);
}
else
{
if (AllocConsole())
{
service.OnStart(args);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
service.OnStop();
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
}
如果代码运行时,由于Windows服务启动,它将作为Windows服务运行。否则,它将分配一个控制台,运行服务,然后在退出服务之前等待按键。您可以在此基础上进行测试暂停并继续。
#1什么 “双重事件触发”? #2你在问什么可能的失败情况是可以触发你的空捕获块? #3什么样的Windows身份验证?你想要认证什么? – 2012-04-04 23:20:11