Hi I have a little situation where I've looking for a better solution. The problem originated where multiple clients are sending messages to a single server program and they have to access one file. Now when the file is in OPEN mode, no other file could access it. So I was getting a problem when one client is using the file and another client tries to use the same file from the server and generated an error. So I used a what I did was to create a while loop structure that worked but I think is inefficient. The pseudo code is:
Code:
boolfound = true
while(boolfound)
{
   try
   {
        File.open();
        bookfound = false; // break out of the while loop
   }
    catch(some exception) {}
}

So I will throw an exception to detect if you're trying to open the file at which point in time the file is already opened. the exception will be thrown, and the while structure will loop. The only way the while structure will break is if the file is opened successfully and the second statement in the try clause executes.

As I said it works fine. However, this solution is not good since it runs up the cpu usage when the while structure is looping. And I'm seeing a lot of problems which could be solved using this but I need a better solution. I was thinking about having some kind of event but I'm still a little confused about having an object wait until another is completed.

So you have two clients, C1 and C2. Both accessing the same server. C1 is currently using a file in the server, C2 is tryin to access the same file. How do I make C2 wait until the file is available again without running up the CPU usage?

Jennifer