🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / dosya kapanıncaya kadar bekle sonra oku

1-) C# RMOS - dosya kapanıncaya kadar bekle sonra oku

 /// <summary>

        /// Blocks until the file is not locked any more.

        /// </summary>

        /// <param name="fullPath"></param>

        bool WaitForFile(string fullPath)

        {

            int numTries = 0;

            while (true)

            {

                ++numTries;

                try

                {

                    // Attempt to open the file exclusively.

                    using (FileStream fs = new FileStream(fullPath,

                        FileMode.Open, FileAccess.ReadWrite,

                        FileShare.None, 100))

                    {

                        fs.ReadByte();

 

                        // If we got this far the file is ready

                        break;

                    }

                }

                catch (Exception ex)

                {

 

                    if (numTries > 10)

                    {

                      

                        return false;

                    }

 

                    // Wait for the lock to be released

                    System.Threading.Thread.Sleep(500);

                }

            }

            return true;

        }

 2021 Ocak 18 Pazartesi
 399