Transfer time estimate

  • Thread starter Thread starter Christophe F. [MS]
  • Start date Start date
C

Christophe F. [MS]

Hello,
I'm looking for sample code in C# that will estimate the transfer time for a
file between two machines (taking into account bandwidth and latency).
 
Christophe,

You can't really do that unless you are in the process of sending the
file. The best you can do is make estimates on each side of the process.

When you begin to sending/receive, store the time. As you send/receive
each group of bytes, you take note of the elapsed time (the current time
minus the start time). Divide that by the number of bytes sent/received to
determine how long it takes to send one byte. Then, multiply that ratio by
the number of bytes left, and you will have the approximate time left to
perform the transfer.

Hope this helps.
 
Thank you Nicholas, I guess I should not use the File.Copy method to
transfer file then, but file streaming?

Nicholas Paldino said:
Christophe,

You can't really do that unless you are in the process of sending the
file. The best you can do is make estimates on each side of the process.

When you begin to sending/receive, store the time. As you send/receive
each group of bytes, you take note of the elapsed time (the current time
minus the start time). Divide that by the number of bytes sent/received
to determine how long it takes to send one byte. Then, multiply that
ratio by the number of bytes left, and you will have the approximate time
left to perform the transfer.

Hope this helps.
 
Christophe,

If you want to have the ability to perform these calculations as the
copy takes place, then yes.

You might also be able to do the same thing with a call to the
SHFileOperation function through the P/Invoke layer. I believe it will
allow you to specify a callback which is called during the operation.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christophe F. said:
Thank you Nicholas, I guess I should not use the File.Copy method to
transfer file then, but file streaming?

Nicholas Paldino said:
Christophe,

You can't really do that unless you are in the process of sending the
file. The best you can do is make estimates on each side of the process.

When you begin to sending/receive, store the time. As you
send/receive each group of bytes, you take note of the elapsed time (the
current time minus the start time). Divide that by the number of bytes
sent/received to determine how long it takes to send one byte. Then,
multiply that ratio by the number of bytes left, and you will have the
approximate time left to perform the transfer.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christophe F. said:
Hello,
I'm looking for sample code in C# that will estimate the transfer time
for a file between two machines (taking into account bandwidth and
latency).
 
Great, I got this exemple to work:
http://www.thecodeproject.com/csharp/csdoesshell2.asp?


--
--
Cdt,
CF
Nicholas Paldino said:
Christophe,

If you want to have the ability to perform these calculations as the
copy takes place, then yes.

You might also be able to do the same thing with a call to the
SHFileOperation function through the P/Invoke layer. I believe it will
allow you to specify a callback which is called during the operation.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christophe F. said:
Thank you Nicholas, I guess I should not use the File.Copy method to
transfer file then, but file streaming?

Nicholas Paldino said:
Christophe,

You can't really do that unless you are in the process of sending the
file. The best you can do is make estimates on each side of the
process.

When you begin to sending/receive, store the time. As you
send/receive each group of bytes, you take note of the elapsed time (the
current time minus the start time). Divide that by the number of bytes
sent/received to determine how long it takes to send one byte. Then,
multiply that ratio by the number of bytes left, and you will have the
approximate time left to perform the transfer.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,
I'm looking for sample code in C# that will estimate the transfer time
for a file between two machines (taking into account bandwidth and
latency).
 
Back
Top