Checking for object lock

Posted on 2012-09-17
Last Modified: 2012-10-01
I am executing some C# code to initiate the creation of a file on our host system (AS/400). Once the file has been created on the AS/400, the AS/400 "pushes" the file over to the Windows server where my C# code is running.
I need to be able to wait until the file is completely over to the Windows server from the AS/400 host before exiting the thread. I would like to set up a while loop to check to see if the object exists and if it is locked. If it does exist and it's not locked, then I should be able to assume it has arrived in the folder on my Windows Server.
Any help would be greatly appreciated!
Question by:Euless_Tech
    1 Comment
    LVL 23

    Accepted Solution

    Why not just try opening the file

    While (True) {
       try {
          FileStream fs = File.Open(path, FileMode.Open, FileAccess.Write, FileShare.None)
       Catch (exception) { System.Threading.Thread.Sleep(500); }
       Finally { fileStream.Close(); }

    Open in new window

    Just tweak the sleep time to suit your application


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now