开发者

Is it possible to create a C# Windows Service that detects new file creation on Windows XP?

开发者 https://www.devze.com 2023-03-28 20:11 出处:网络
I have a folder that will contain a temporary file that will be created by web service. I want the file to be converted by .exe program I have via command line. Now, I have already generated web servi

I have a folder that will contain a temporary file that will be created by web service. I want the file to be converted by .exe program I have via command line. Now, I have already generated web service that will create file and store in one specific folder.

Here is the scenario:

  1. Web service receive amr byte data from my mobile app.
  2. Web service deletes all files existing in the folder. (to remove .amr file and .mp3 file that was generated from the previous round)
  3. Web service create new .amr file in the folder.
  4. Windows Service detects that there is a new file created. It call converter.exe. Once complete, it creates .mp3 file in the same folder.

Now, I have no problem with step1-3. The problem is step4, which I need to convert .amr file to .mp3 file. In order to do this, I need to pass some dos-command to converter.exe. I found that it is impossible for me to do it from my web service, so I am thinking of creating C# Windows Service that will watch the folder storing the files. Is it possible to create Windows Service that is able to detect new file creation and run converter.exe as soon as a new file is created ? I did search on the Internet and found that I may be create Windows Service with FileSystemWatcher, but i am just not sure if it will be possible.

The reason I found when trying to execute converter.exe from web service is about permission. I did everything but still can't make it success.(Using Web Service, converter.exe is shown on the process list in task manager as local system, but it will not be executed because of some security reason...) Hope there will be no security problem when I try to execute converter.exe using Windows Se开发者_开发问答rvice.

Thanks in advance for all answers and suggestions :)


System.IO.FileSystemWatcher will do the trick. The Created event will tell you when a file has been created in the directory you're watching. To start your conversion program, take a look at the System.Diagnostics.Process.Start method. Both of these should work fine in a Windows service.

0

精彩评论

暂无评论...
验证码 换一张
取 消