문제

I am trying to get an application (written in c#) to run on a windows mobile 6.1 device, in the background (with a filesystemwatcher) behind another application. I have written a simple filesystemwatcher, which works great as long as its the current application (in other words as long as you dont open another program after it). Even after returning to the instance, the filesystemwatcher no longer functions. Its using OpenNETCF, as .net cf doesnt include a file system watcher.

Anyone know why this wouldnt be working?

any help would be greatly appreciated.

here is my code:

    private void Form1_Load(object sender, EventArgs e)
    {

        OpenNETCF.IO.FileSystemWatcher f = new OpenNETCF.IO.FileSystemWatcher(@"c:\happydays", "*.*");
        f.IncludeSubdirectories = true;
        f.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite |
                       NotifyFilters.FileName | NotifyFilters.DirectoryName;

        f.Created += new FileSystemEventHandler(File_Created);                                  
        f.EnableRaisingEvents = true;
    }

    private void File_Created(object sender, OpenNETCF.IO.FileSystemEventArgs e)
    {
MessageBox.Show("File Created");
    }
도움이 되었습니까?

해결책

I'm not certain why you'd get that behavior, but I can hazard a guess that the OS is dispatching the file notification messages only to the active application.

The SDF's FileSystemWatcher is dependent on the application message pump to operate because it uses the aygshell APIs under the hood, and aygshell uses Windows messages for dispatching (Microsoft's choice, not mine). I didn't like that for several reasons, so I wrote an alternative called the FileSystemMonitor that you'll find in the same namespace and DLL and the FileSystemWatcher. IIRC, it doesn't work 100% identical but I made it as close as possible given the file system APIs that I had to work with.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top