inside the while(true) loop.
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
"CK" <john88m@hotmail.com> wrote in message
news:O6otH2U5EHA.1300@TK2MSFTNGP14.phx.gbl...
> I tried FileSystemWatcher but it wont work when I insert a file into the
> directory. it works only when I change something in the file, delete the
> file. its basicly changes within the directory not adding a file into the
> directory.
> I did try the treading and its better except I dont know where in the code
i
> should try the tread.sleep() method.
>
> Thanks
>
>
>
> "Nigel Armstrong" <NigelArmstrong@discussions.microsoft.com> wrote in
> message news:5A4DC510-BC85-4FAE-AC25-7B2715010ADB@microsoft.com...
> > Hi CK
> >
> > You should try using the FileSystemWatcher component. This does exactly
> > what
> > you want. Your code seems to be in a tight loop, hence the problem! With
> > the
> > FileSystemWatcher, you get a notification when a file addition (or
> > modification or deletion) occurs in the watched directory.
> >
> > Try this URL for a useful article in MSDN magazine:
> >
> >
http://msdn.microsoft.com/msdnmag/issues/01/07/vbnet/ > >
> > HTH
> >
> > Nigel Armstrong
> >
> > "CK" wrote:
> >
> >> I need a windows service that listens to a directory , if any xml file
is
> >> placed in the directory it reads it and calls a class and receives a
> >> string.. this is the code I came up with. it works but it kills my
> >> processor
> >> after a few min. what should i do??
> >>
> >> Thanks
> >>
> >> private void button6_Click(object sender, System.EventArgs e)
> >>
> >> {
> >>
> >> NewClaims.clsNewClaims objNewClaimI = new NewClaims.clsNewClaims();
> >>
> >>
> >>
> >> while (true)
> >>
> >> {
> >>
> >> //Get the File in the directory
> >>
> >> DirectoryInfo dir = new DirectoryInfo(@"C:\test4");
> >>
> >> FileInfo[] xmlfiles = dir.GetFiles("*.xml");
> >>
> >> foreach( FileInfo file in xmlfiles)
> >>
> >> {
> >>
> >> string strHMI="";
> >>
> >> //Opens an existing UTF-8 encoded text file for reading.
> >>
> >> StreamReader sr = File.OpenText(file.FullName);
> >>
> >> string data= sr.ReadToEnd();
> >>
> >>
> >> strHMI = objNewClaimI.ConvertNewClaimsXmlUICIToHMItxt(data);
> >>
> >> int intExtension=file.Name.IndexOf(".");
> >>
> >> FileInfo outputFile = new
> >> FileInfo(@"c:\test5\"+file.Name.Substring(0,intExtension)+".txt");
> >>
> >> StreamWriter strWriter =new StreamWriter(File.Open(@"c:\test5\" +
> >> file.Name.Substring(0,intExtension) +".txt",FileMode.Create,
> >> FileAccess.Write ));
> >>
> >> strWriter.Flush();
> >>
> >> strWriter.Write(strHMI.ToString());
> >>
> >>
> >> strWriter.Close();
> >>
> >> sr.Close();
> >>
> >> file.Delete();
> >>
> >> }
> >>
> >>
> >> }
> >>
> >> }
> >>
> >>
> >>
>
>