FTP文件上传,点击Int Maxvalue ..如何到处走? [英] FTP file upload, hits the Int Maxvalue.. How to get around?

查看:50
本文介绍了FTP文件上传,点击Int Maxvalue ..如何到处走?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我的上传达到2gb时程序崩溃。我正在使用带有进度条的backgroundworker。



这里需要一点帮助...... :)



  private   void  backgroundWorker1_DoWork_1(对象发​​件人,DoWorkEventArgs e)
{
var ftpWebRequest =(FtpWebRequest)WebRequest.Create( ftp://example.com/ + clientlabel.Text + / + Path.GetFileName(zipfile));
ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpWebRequest.Credentials = new NetworkCredential(FTPuser,FTPpass);
使用 var inputStream = File.OpenRead(zipfile))
使用 var outputStream = ftpWebRequest.GetRequestStream())
{
var buffer = new byte [ 1024 * 1024 ];
int totalReadBytesCount = 0 ;
int readBytesCount;
while ((readBytesCount = inputStream.Read(buffer, 0 ,buffer.Length)) > 0
{
outputStream.Write(buffer, 0 ,readBytesCount);
totalReadBytesCount + = readBytesCount;
var progress = totalReadBytesCount * 100 0 / inputStream.Length;
double totalbyte =(totalReadBytesCount / 1024 )/ 1024 ;
double uploadbyte =(inputStream.Length / 1024 )/ 1024 ;
label2.Text = 上传: + totalbyte + + uploadbyte + MB;
backgroundWorker1.ReportProgress(( int )进度);
}
}
}

private void backgroundWorker1_ProgressChanged_1( object sender,ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}





我得到的错误:

System.ArgumentOutOfRangeException :Værdien'-44'er ugyldig for'Value'。 '价值'skalværemellem'最小'og'最大值'。 Parameternavn:Value ved System.Windows.Forms.ProgressBar.set_Value(Int32 value)

对不起丹麦语错误代码。



而且我的Label2在2000mb左右开始时开始运行负值

我能看到的,它关于Int MaxValue的东西我正在点击..

有没有办法呢?

解决方案

C#的新手?只是一点建议:在你完善C#知识之前掌握断点和其他调试问题。



我总是建议:甚至不要开始开发项目之前从开头到最后,你至少阅读过一次语言和平台手册。但这与短项目无关,也许在阅读时你需要做的几行。那些不这样做的人,通常会高估他们的理解水平,只是在他们开始写作的时候积累挫折感。那么,你应该在什么时候尝试调试?我建议:在你创建第一个学习项目的那一刻。一旦你学会了如何编写方法,传递一些参数,调用它,就可以在它上面使用调试器了。如果您错过了那一刻,请将您正在做的所有事情放在一边并进入调试器。然后阅读整个手册,至少在每个主题上做一些练习。到达手册的最后。



一旦准备就绪,请使用ZoltánZörgő的建议;那么你当然应该搞清楚。我的计划怎么样?



当你感到舒服时,你可能会在没有任何调试的情况下编写90%-97%的代码。这取决于您的问题的复杂性和您当前的经验。目前,运行时的任何微小问题都应引导您进入调试器会话,并在此论坛上提出任何问题。



-SA

Every time my upload hits 2gb the program crashes. I'm using backgroundworker with progressbar.

Need a little help here... :)

private void backgroundWorker1_DoWork_1(object sender, DoWorkEventArgs e)
{
    var ftpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://example.com/" + clientlabel.Text + "/" + Path.GetFileName(zipfile));
    ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
    ftpWebRequest.Credentials = new NetworkCredential(FTPuser, FTPpass);
    using (var inputStream = File.OpenRead(zipfile))
    using (var outputStream = ftpWebRequest.GetRequestStream())
    {
        var buffer = new byte[1024 * 1024];
        int totalReadBytesCount = 0;
        int readBytesCount;
        while ((readBytesCount = inputStream.Read(buffer, 0, buffer.Length)) > 0)
        {
            outputStream.Write(buffer, 0, readBytesCount);
            totalReadBytesCount += readBytesCount;
            var progress = totalReadBytesCount * 100.0 / inputStream.Length;
            double totalbyte = (totalReadBytesCount / 1024) / 1024;
            double uploadbyte = (inputStream.Length / 1024) / 1024;
            label2.Text = "Uploading: " + totalbyte + " of " + uploadbyte + "Mb";
            backgroundWorker1.ReportProgress((int)progress);
        }
    }
}

private void backgroundWorker1_ProgressChanged_1(object sender, ProgressChangedEventArgs e)
{
    progressBar1.Value = e.ProgressPercentage;
}



The error i get:
System.ArgumentOutOfRangeException: Værdien '-44' er ugyldig for 'Value'. 'Value' skal være mellem 'minimum' og 'maximum'. Parameternavn: Value ved System.Windows.Forms.ProgressBar.set_Value(Int32 value)
Sorry for Danish Error code.

And my Label2 is starting to run negative when it hits around 2000mb
What i can see, its something about the Int MaxValue i'm hitting..
Is there a way around it?

解决方案

"New to C#"? Just a little advice: master "break points" and other debugging issues even before you refine you C# knowledge.

I always advise: don't even start developing projects before you read the language and platform manuals at least once, from the very beginning to the very end. But this is not related to the short projects, maybe few lines each you need to do while reading. People who don't do it, usually overestimate the level of their understanding and just accumulate frustration to the point they start writing. So, at what moment of time should you try to debug? I would advise: at the moment of time when you create your very first study project. As soon as you learn how to write a method, pass some parameters, call it, it's time to use the debugger on it. If you missed that moment, set aside all you are doing and get into the debugger. And then read the whole manual doing at least some exercises on each topic. Reach the very end of the manual.

As soon as are ready, use the advice by Zoltán Zörgő; then you should certainly figure things out. How's my plan?

And when you get comfortable, you may come to the point when you write some 90%-97% of code without any debugging at all. It will depend on complexity of your problems and your current experience. For now, any tiny concern of your runtime should lead your to the debugger session, as well as asking any questions on this forum.

—SA


这篇关于FTP文件上传,点击Int Maxvalue ..如何到处走?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆