J'ai le code suivant pour limiter la vitesse de téléchargement de fichiers pour une application;Limitation de bande passante pour le téléchargement de fichiers
context.Response.Buffer = false;
context.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + arquivo.Nome);
context.Response.AppendHeader("Content-Type",
"application/octet-stream");
context.Response.AppendHeader("Content-Length",
arquivo.Tamanho.ToString());
int offset = 0;
byte[] buffer = new byte[currentRange.OptimalDownloadRate];
while (context.Response.IsClientConnected && offset < arquivo.Tamanho)
{
DateTime start = DateTime.Now;
int readCount = arquivo.GetBytes(buffer, offset, // == .ExecuteReader()
(int)Math.Min(arquivo.Tamanho - offset, buffer.Length));
context.Response.OutputStream.Write(buffer, 0, readCount);
offset += readCount;
CacheManager.Hit(jobId, fileId.ToString(), readCount, buffer.Length, null);
TimeSpan elapsed = DateTime.Now - start;
if (elapsed.TotalMilliseconds < 1000)
{
Thread.Sleep(1000 - (int)elapsed.TotalMilliseconds);
}
}
Comme toujours, il fonctionne très bien dans mon développement, les environnements internes d'assurance qualité et des clients, mais il lance une exception dans un environnement de production:
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.SleepInternal(Int32 millisecondsTimeout)
at (...).Handlers.DownloadHandler.processDownload(HttpContext context, ...)
Pour l'utilisateur, une nouvelle fenêtre ouvre sur boîte de dialogue de téléchargement:
The connection with the server was reset
avez-vous une idée de ce qui se passe?
Je n'ai pas la réponse, mais il semble que ce soit commun: http://www.google.com/search?q=SleepInternal+threadabortexception – asveikau