?
Solved

Checking for object lock

Posted on 2012-09-17
1
Medium Priority
?
449 Views
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!
0
Comment
Question by:Euless_Tech
1 Comment
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 total points
ID: 38407880
Why not just try opening the file

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

Open in new window

Just tweak the sleep time to suit your application

Michael
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

807 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