windows service not working for everyone.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayush patel
    New Member
    • Jul 2008
    • 63

    #16
    i guess none of the classes are getting executed. because i added

    Code:(text)

    static void Main()
    {
    System.Diagnost ics.Debugger.La unch();


    and tried debugging the service i dont think system ever reaches to that place for me to debug and see where it is crashing.

    Comment

    • ayush patel
      New Member
      • Jul 2008
      • 63

      #17
      Ok,

      I debugged it somehow and this is what I am getting

      An unhandled exception of type 'System.IO.File NotFoundExcepti on' occurred in mscorlib.dll

      Additional information: Could not find file 'C:\W080805.TXT '.


      W080805.TXT' is the file that is being placed in the folder and the service has to pick it up. that file is still in the folder and I am getting this error.

      Any idea why this is happening.
      Ayush

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #18
        Originally posted by ayush patel
        Ok,

        I debugged it somehow and this is what I am getting

        An unhandled exception of type 'System.IO.File NotFoundExcepti on' occurred in mscorlib.dll

        Additional information: Could not find file 'C:\W080805.TXT '.


        W080805.TXT' is the file that is being placed in the folder and the service has to pick it up. that file is still in the folder and I am getting this error.

        Any idea why this is happening.
        Ayush
        Is C: on the local machine or the remote machine? Does the file for sure exist?

        Comment

        • ayush patel
          New Member
          • Jul 2008
          • 63

          #19
          yes c is in local mahcine i have inserted two files before which are picked up by the service. third one is giving this error. file exists because i have copy pasted it in to that folder for the service to pick it up.

          Comment

          • ayush patel
            New Member
            • Jul 2008
            • 63

            #20
            its very wierd but sometimes I am getting this error


            An unhandled exception of type 'System.IO.IOEx ception' occurred in mscorlib.dll

            Additional information: The process cannot access the file 'C:\W080716.TXT ' because it is being used by another process.

            W080716.TXT' file is not open anywhere.

            Comment

            • balabaster
              Recognized Expert Contributor
              • Mar 2007
              • 798

              #21
              Originally posted by ayush patel
              its very wierd but sometimes I am getting this error


              An unhandled exception of type 'System.IO.IOEx ception' occurred in mscorlib.dll

              Additional information: The process cannot access the file 'C:\W080716.TXT ' because it is being used by another process.

              W080716.TXT' file is not open anywhere.
              Does your own application open this file anywhere and not dispose of connections to it? I sometimes see this if I've forgotten a:

              sw.close()
              sw.dispose()

              On the streamwriter that's accessing the file...

              Comment

              • ayush patel
                New Member
                • Jul 2008
                • 63

                #22
                no everytime i opened a StreamWriter I have closed it.

                Comment

                • balabaster
                  Recognized Expert Contributor
                  • Mar 2007
                  • 798

                  #23
                  Originally posted by ayush patel
                  no everytime i opened a StreamWriter I have closed it.
                  Sorry man, then without seeing your code, I've eliminated everything I can think of.

                  Comment

                  • ayush patel
                    New Member
                    • Jul 2008
                    • 63

                    #24
                    hmm.. i know thanks for trying anyway. I will post my solution if i find any.
                    Ayush

                    Comment

                    • PRR
                      Recognized Expert Contributor
                      • Dec 2007
                      • 750

                      #25
                      "System.Tim ers" is better option...
                      what i had suggested was that you should try to pause... when the watcher event is called....
                      Also try and optimized the buffer size:
                      FileSystemWatch er..InternalBuf ferSize Property .. the default is around 4K which can handle around 400 request per second... (if i am not wrong)..

                      I would suggest you do this:
                      1.First Pause on
                      Code:
                      private static void OnChanged(object source, FileSystemEventArgs e)
                              {
                                  Thread.Sleep(1000);
                                  // This is enable the file to be tranfered before your code goes off..
                      
                              }
                      2. Instead Of writing all processin in OnChanged... Try doin this: inside onchanged ... write to Database the file name and processing status as "False"
                      3. Periodically run a function using timers to do processin on the file... this way if too many files are put up... then your service wont be creating large number of threads...
                      4. For testing purpose ... put your code in console program and check... Finally you can transfer to a windows service..

                      Comment

                      • ayush patel
                        New Member
                        • Jul 2008
                        • 63

                        #26
                        Hi,

                        I thought the problem may be as you said before: ownership of file is not available to watcher as soon as file is created.so I used Thread.Sleep(10 00);I also increased the buffersize of filewatcher. but still the service throws an error that the file that i just copied into the folder is not available. it is not recognizing the file atall.

                        this service is not used very frequently so there is no problem of processing many files at once.only one file is loaded that too may be 3 times a week.

                        do you have any idea why does it say

                        An unhandled exception of type 'System.IO.File NotFoundExcepti on' occurred in mscorlib.dll

                        Additional information: Could not find file 'C:\W080805.TXT '.
                        Ayush

                        Comment

                        • balabaster
                          Recognized Expert Contributor
                          • Mar 2007
                          • 798

                          #27
                          I wonder if the network share may be an issue? What is intriguing is that the FileSystemWatch er flags the file as having been created, but that System.IO.FileE xists returns false...

                          Did you try wrapping the copy in:
                          VB:
                          Code:
                          If System.IO.FileExists(e.FullPath) Then
                          ...
                          End If

                          Comment

                          • PRR
                            Recognized Expert Contributor
                            • Dec 2007
                            • 750

                            #28
                            Originally posted by ayush patel

                            I thought the problem may be as you said before: ownership of file is not available to watcher as soon as file is created.so I used Thread.Sleep(10 00);I also increased the buffersize of filewatcher. but still the service throws an error that the file that i just copied into the folder is not available. it is not recognizing the file atall.

                            this service is not used very frequently so there is no problem of processing many files at once.only one file is loaded that too may be 3 times a week.

                            do you have any idea why does it say

                            An unhandled exception of type 'System.IO.File NotFoundExcepti on' occurred in mscorlib.dll

                            Additional information: Could not find file 'C:\W080805.TXT '.
                            Ayush
                            wow... now i m run out of ideas ... try testing it from another pc.... one more thing post your code where exception occurs and also the full exception message and stacktrace
                            i will go through ur post again .. n find something .. that will be 2moro.. meanwhile give as much info as possible ... so that we can trace the error...

                            as u have mentioned u r not using "C:\W080805.TXT "...still wats d content of it...

                            Comment

                            • ayush patel
                              New Member
                              • Jul 2008
                              • 63

                              #29
                              after a lot of work i found a work around not a solution though.i used Thread.Sleep(60 00); and also i placed FileWatch_Creat ed code in if loop saying if any file exists then read it else go to FileWatch_Creat ed again.

                              because as i increase the time in thread.sleep the service was getting delayed. so now till the service finds a file it will remain in the if else loop. it wont be a infinite loop since it is going to find a file eventually. there is a creation of file that is why it has entered into FileWatch_Creat ed event.

                              i dont think this is the best method but it worked.
                              Thanks to all who helped.

                              Ayush

                              Comment

                              • balabaster
                                Recognized Expert Contributor
                                • Mar 2007
                                • 798

                                #30
                                Originally posted by ayush patel
                                after a lot of work i found a work around not a solution though.i used Thread.Sleep(60 00); and also i placed FileWatch_Creat ed code in if loop saying if any file exists then read it else go to FileWatch_Creat ed again.

                                because as i increase the time in thread.sleep the service was getting delayed. so now till the service finds a file it will remain in the if else loop. it wont be a infinite loop since it is going to find a file eventually. there is a creation of file that is why it has entered into FileWatch_Creat ed event.

                                i dont think this is the best method but it worked.
                                Thanks to all who helped.

                                Ayush
                                Sorry you couldn't find a more ideal solution - it does seem like a bit of a hack to do it that way. But at least you have something until you find a way to resolve the issue properly...

                                Comment

                                Working...