C# 文件传输的远程流不读取
我编写了一些“更新程序”,以使 .exe 为我的开发团队的其他成员保持最新状态。以前工作正常,但突然就停止工作了。
我已经注意到这个问题:我的远程流无法开始读取。
Uri patch = new Uri("http://********/*********/" + GetVersion().ToString() + ".exe");
Int64 patchsize = PatchSize(patch);
var CurrentPath = String.Format("{0}\\", Environment.CurrentDirectory);
Int64 IntSizeTotal = 0;
Int64 IntRunning = 0;
string strNextPatch = (version + ".exe");
using (System.Net.WebClient client = new System.Net.WebClient())
{
using (System.IO.Stream streamRemote = client.OpenRead(patch))
{
using (System.IO.Stream streamLocal = new FileStream(CurrentPath + strNextPatch, FileMode.Create, FileAccess.Write, FileShare.None))
{
int intByteSize = 0;
byte[] byteBuffer = new Byte[IntSizeTotal];
while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
{
streamLocal.Write(byteBuffer, 0, intByteSize);
IntRunning += intByteSize;
double dIndex = (double)(IntRunning);
double dTotal = (double)byteBuffer.Length;
double dProgressPercentage = (dIndex / dTotal);
int intProgressPercentage = (int)(dProgressPercentage * 100);
worker.ReportProgress(intProgressPercentage);
}
streamLocal.Close();
}
streamRemote.Close();
GetVersion() 仅返回 .exe 的当前服务器版本的当前版本号。 问题出在这里:
while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
我的streamRemote 只是不返回任何字节,因此这个while 子句没有被填充。
对我有什么建议吗?
i have written a little "Update Programm" to keep an .exe up to date for the rest of my dev team. It used to work fine, but suddenly it stopped working.
I already noticed the problem: my remote stream does not start to read.
Uri patch = new Uri("http://********/*********/" + GetVersion().ToString() + ".exe");
Int64 patchsize = PatchSize(patch);
var CurrentPath = String.Format("{0}\\", Environment.CurrentDirectory);
Int64 IntSizeTotal = 0;
Int64 IntRunning = 0;
string strNextPatch = (version + ".exe");
using (System.Net.WebClient client = new System.Net.WebClient())
{
using (System.IO.Stream streamRemote = client.OpenRead(patch))
{
using (System.IO.Stream streamLocal = new FileStream(CurrentPath + strNextPatch, FileMode.Create, FileAccess.Write, FileShare.None))
{
int intByteSize = 0;
byte[] byteBuffer = new Byte[IntSizeTotal];
while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
{
streamLocal.Write(byteBuffer, 0, intByteSize);
IntRunning += intByteSize;
double dIndex = (double)(IntRunning);
double dTotal = (double)byteBuffer.Length;
double dProgressPercentage = (dIndex / dTotal);
int intProgressPercentage = (int)(dProgressPercentage * 100);
worker.ReportProgress(intProgressPercentage);
}
streamLocal.Close();
}
streamRemote.Close();
GetVersion() only returns the current version number of the current server version of the .exe.
The problem lies here:
while ((intByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
My streamRemote just does not return any bytes so this while clause is not filled.
Any advice for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信问题出在服务器上。我会运行一些检查:
I believe the problem is on the server. I'd run some checks: