public static DownloadProgressChangedEventHandler fProgress(ParamHttp _oParam) { Action <object, DownloadProgressChangedEventArgs> action = (sender, e) => { try{ double bytesIn = e.BytesReceived; //d//ouble totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); double totalBytes = e.TotalBytesToReceive; // double totalBytes = -1; double _nApMax = 104857600; _oParam.nBytes = bytesIn; _oParam.nTotalBytes = totalBytes; if (totalBytes == -1) //Aproximative value { double _nRatio = _oParam.nBytes / 100000000.0; _oParam.nAprox += (_oParam.nBytes - _oParam.nLastBytes) / ((_nRatio * _nRatio) + 1); if (_oParam.nAprox > _nApMax) { _oParam.nAprox = _nApMax; } _oParam.nPercentage = _oParam.nAprox * 97.0 / _nApMax; //Aprox Max was 90% } else { _oParam.nPercentage = bytesIn / totalBytes * 100; } _oParam.nLastBytes = _oParam.nBytes; // Debug.fTrace("pc" + _oParam.nPercentage + " bytesIn " + bytesIn + " totalBytes " + totalBytes); _oParam.dProgress(_oParam); } catch (Exception ex) { _oParam.bFail = true; _oParam.sFailMsg = ex.Message; } }; return(new DownloadProgressChangedEventHandler(action)); }
/* * public static void fProgress(Object sender, RunWorkerCompletedEventArgs e) { * ParamHttp _oParam = (ParamHttp)e.Result; * _oParam.dComplete(_oParam); * }*/ public static void fUrlProgress(ParamHttp _oParam) { try{ // double bytesIn = e.BytesReceived; //d//ouble totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); // double totalBytes = e.TotalBytesToReceive; // double totalBytes = -1; double _nApMax = 104857600; // _oParam.nBytes = bytesIn; // _oParam.nTotalBytes= totalBytes; if (_oParam.nTotalBytes <= 0) //Aproximative value { double _nRatio = _oParam.nBytes / 100000000.0; _oParam.nAprox += (_oParam.nBytes - _oParam.nLastBytes) / ((_nRatio * _nRatio) + 1); if (_oParam.nAprox > _nApMax) { _oParam.nAprox = _nApMax; } _oParam.nPercentage = _oParam.nAprox * 97.0 / _nApMax; //Aprox Max was 90% } else { _oParam.nPercentage = _oParam.nBytes / _oParam.nTotalBytes * 100; } _oParam.nLastBytes = _oParam.nBytes; // Debug.fTrace("pc" + _oParam.nPercentage + " bytesIn " + bytesIn + " totalBytes " + totalBytes); _oParam.dProgress(_oParam); } catch (Exception ex) { _oParam.bFail = true; _oParam.sFailMsg = ex.Message; } }