Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
FtpWebRequest async giving me file lock problems

Answered FtpWebRequest async giving me file lock problems

  • Sunday, April 29, 2012 6:55 PM
     
      Has Code

    Hi All!

    i have written a small app that:

    -Periodically captures a portion of a screen to jpeg file

    -Uploads this file to ftp server

    At first i used 

    My.Computer.Network.UploadFile

    and it worked like a charm. Then i wanted to move to FtpWebRequest async. The reason was because i implemented a global keyboard hook and locking the main thread for upload, disabled my keyboard.

    I copied the example in MSDN regarding FtpWebRequest. the problem i have is that it seems that the file that is being uploaded is locked even after the stream is closed.

    MSDN code used: FtpWebRequest MSDN

    The timer calls a function to upload the image. In that function a bitmap is created and finally:

    bm_dest.Save(imgFile, ImageFormat.Jpeg)

    and after that i am calling the sub for async ftp upload based on msdn example. After one or two successful uploads, i get a general GDI+ exception which comes because "the file is being used from another process"..If i save to a new file is ok.

    I have tried with long intervals in timer (>minute) and it does the same. The file is small (usually 40-50 kb)

    I tested that the stream is closed and tried to press the upload manually 10 secs after and i got the same error.

    I can't figure out what is happening...


    Elias


    • Edited by e4rthdog Sunday, April 29, 2012 6:56 PM
    •  

All Replies

  • Monday, April 30, 2012 1:50 PM
     
     Answered
    Check your program again and again, there must be a operation locking the file.

    Ghost,
    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    • Marked As Answer by e4rthdog Monday, April 30, 2012 1:52 PM
    •