void WriteCacheToFile(MemoryStream downloadCache, int cachedSize)
{
// Lock other threads or processes to prevent from writing data to the file.
lock (fileLocker)
{
using (FileStream fileStream = new FileStream(DownloadPath, FileMode.Open))
{
byte[] cacheContent = new byte[cachedSize];
downloadCache.Seek(0, SeekOrigin.Begin);
downloadCache.Read(cacheContent, 0, cachedSize);
fileStream.Seek(DownloadedSize + StartPoint, SeekOrigin.Begin);
fileStream.Write(cacheContent, 0, cachedSize);
}
}
}