Skip to content

Commit

Permalink
handle canceled WebRequest error and properly dispose of streams
Browse files Browse the repository at this point in the history
  • Loading branch information
cdsboy committed Jan 5, 2012
1 parent 78da7af commit 3ed37dd
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/csharp/Plupload/FileReference.cs
Expand Up @@ -261,6 +261,16 @@ public class FileReference {
if (!this.stopped) {
this.stopped = true;
req.Abort();

if (fileStream != null) {
fileStream.Dispose();
fileStream = null;
}

if (imageStream != null) {
imageStream.Dispose();
imageStream = null;
}
}
}

Expand Down Expand Up @@ -414,17 +424,26 @@ public class FileReference {
}

private void ResponseCallback(IAsyncResult ar) {
try {
HttpWebRequest request = ar.AsyncState as HttpWebRequest;
try
{
HttpWebRequest request = ar.AsyncState as HttpWebRequest;

WebResponse response = request.EndGetResponse(ar);
WebResponse response = request.EndGetResponse(ar);

syncContext.Post(ExtractResponse, response);
} catch (Exception ex) {
syncContext.Send(delegate {
this.OnIOError(new ErrorEventArgs(ex.Message, this.chunk, this.chunks));
}, this);
}
syncContext.Post(ExtractResponse, response);
}
catch (WebException ex) {
if (ex.Status != WebExceptionStatus.RequestCanceled) {
syncContext.Send(delegate {
this.OnIOError(new ErrorEventArgs(ex.Message, this.chunk, this.chunks));
}, this);
}
}
catch (Exception ex) {
syncContext.Send(delegate {
this.OnIOError(new ErrorEventArgs(ex.Message, this.chunk, this.chunks));
}, this);
}
}

private void ExtractResponse(object state) {
Expand Down

0 comments on commit 3ed37dd

Please sign in to comment.