CClash.FileUtils.CopyUnlocked C# (CSharp) Method

CopyUnlocked() public static method

public static CopyUnlocked ( string from, string to ) : void
from string
to string
return void
        public static void CopyUnlocked(string from, string to)
        {
            int attempts = FileIORetryCount;
            do
            {
                try
                {
                    using (var ifs = new FileStream(from, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (var ofs = new FileStream(to, FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            ifs.CopyTo(ofs);
                            return;
                        }
                    }
                }
                catch (IOException)
                {
                    attempts--;
                    if (attempts == 0) throw;
                    System.Threading.Thread.Sleep(FileIORetrySleep);
                }
            } while (true);
        }

Usage Example

Example #1
0
        public void AddFile(string key, string filePath, string contentName)
        {
            EnsureKey(key);
            var target = MakePath(key, contentName);

            FileUtils.CopyUnlocked(filePath, target);

            if (Added != null)
            {
                Added(this, new FileCacheStoreAddedEventArgs()
                {
                    SizeKB = (int)(new FileInfo(filePath).Length / 1024)
                });
            }
        }
All Usage Examples Of CClash.FileUtils::CopyUnlocked