Files
mono/mcs/class/System/System.Net/DownloadProgressChangedEventArgs.cs
T
Miguel de Icaza 737ee8e35c 2007-12-12 Miguel de Icaza <[email protected]>
* WebClient.cs (DownloadFileCore): use longs for the
	ContentLength, although the other code (loading into a byte array,
	or a string) still uses ints, the DownloadFileCore should not.

2007-12-11  Miguel de Icaza  <[email protected]>

	* WebClient.cs: 

	Lots of fixes to get the *Async methods to work.
	
	* WebClient.cs: async, new boolean flag, used to track whether we
	are an async invocation, and if so, we need to invoke some
	methods. 

	Switch to using System.Threading.Thread instead of the ThreadPool
	as there is no way with the ThreadPool to abort threads (to
	implemente CancelAsync). 

	(CompleteAsync): Helper method used to clear the state after an
	async operation completes, otherwise the WebClient can only be
	used once. 

	(CancelAsync): Use Thread.Interrupt to signal the thread that we
	are aborting it (it is a lot milder than Thread.Abort, and we are
	in no rush to cancel this anyways); Also the documentation states
	that we need to call the WebRequest.Abort method, so we do that in
	every Download instance.

	(DownloadDataAsync, DownloadFileAsync, DownloadStringAsync,
	OpenReadAsync, OpenWriteAsync, UplaodDataAsync, UploadFileAsync,
	UploadStringAsync): Make signature parameters match MS; use
	threads instead of threadpool (so we can implement CancelAsync),
	catch ThreadAbortException here so we can also raise the proper
	DownloadDataCompleteEventArgs.

	These routines will also call the WebRequest.Abort when
	appropriate when ThreadInterrupted is used.
	
	(ReadAll): Raise DownloadProgressChanged events.


svn path=/trunk/mcs/; revision=91142
2007-12-12 05:24:52 +00:00

59 lines
1.8 KiB
C#

//
// DownloadProgressChangedEventArgs.cs
//
// Author:
// Atsushi Enomoto <[email protected]>
//
// (C) 2006 Novell, Inc. (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.ComponentModel;
using System.IO;
namespace System.Net
{
public class DownloadProgressChangedEventArgs : ProgressChangedEventArgs
{
internal DownloadProgressChangedEventArgs (long bytesReceived, long totalBytesToReceive, object userState)
: base (totalBytesToReceive != -1 ? ((int)(bytesReceived * 100 / totalBytesToReceive)) : 0, userState)
{
this.received = bytesReceived;
this.total = totalBytesToReceive;
}
long received, total;
public long BytesReceived {
get { return received; }
}
public long TotalBytesToReceive {
get { return total; }
}
}
}
#endif