Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Application closes with while loop running?

Hey, I currently have a while loop running in my application (download and execute from link) and it seems that my stub shuts itself down even though I have a while loop running and have not instructed it to close.

Code
    public static void Persistance(FileInfo file) {
    
    while(true) {
        if(!IsFileinUse(file)) {
             StartFile(file.FullName);
        }
    }    
    }

Code
        if(persistance) {
            IsFileinUse(file);
        }

Code
public static bool IsFileinUse(FileInfo file)
{
     FileStream stream = null;

     try
     {
         stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
     }
     catch (IOException)
     {
         return true;
     }
     finally
     {
         if (stream != null)
         stream.Close();
     }
     return false;
}
You should click here.
Is this your UI thread? (If you have a UI ofc)
at first I'd suspect that the stream.Close() causes an exception and that makes it fall out of the while loop on exception. but not sure.
eh...
Debug it. See when it exits the loop.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by VelvetCodingApr 17, 2019 09:39 PM 1 200 Apr 17, 2019 09:39 PM
Last Post: SIM-3991524
[Java] by TennoFeb 3, 2019 04:49 AM 4 300 Feb 3, 2019 04:49 AM
Last Post: Tenno
[C] by Camf ∆Mar 19, 2018 10:24 PM 20 572 Mar 19, 2018 10:24 PM
Last Post: 0xDEAD10CC