Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sing System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- using System.IO;
- using System.Threading;
- namespace Letoltesvezerlo
- {
- public partial class Form1 : Form
- {
- private Thread thrLetolt;
- private Stream strValasz;
- private Stream strHelyiMentes;
- private HttpWebRequest webKerelem;
- private HttpWebResponse webValasz;
- private static int LetoltesSzazalek;
- private delegate void UpdateProgessCallback(Int64 BytesRead, Int64 TotalBytes);
- public Form1()
- {
- InitializeComponent();
- }
- private void btnLetoltes_Click(object sender, EventArgs e)
- {
- lblFolyamat.Text = "Letöltés elkezdve!";
- thrLetolt = new Thread(new ThreadStart(Letolt));
- thrLetolt.Start();
- }
- private void UpdateProgress(Int64 BytesRead, Int64 TotalBytes)
- {
- LetoltesSzazalek = Convert.ToInt32((BytesRead * 100) / TotalBytes);
- prgLetolt.Value = LetoltesSzazalek;
- lblFolyamat.Text = "ennyi van letöltve " + BytesRead + " -ből " + TotalBytes + " (" + LetoltesSzazalek + "%)";
- }
- private void Letolt()
- {
- using (WebClient wcDownload = new WebClient())
- {
- try
- {
- webKerelem = (HttpWebRequest)WebRequest.Create(textBoxUrl.Text);
- webKerelem.Credentials = CredentialCache.DefaultCredentials;
- webValasz = (HttpWebResponse)webKerelem.GetResponse();
- Int64 fileSize = webValasz.ContentLength;
- strValasz = wcDownload.OpenRead(textBoxUrl.Text);
- strHelyiMentes = new FileStream(textBoxUtvonal.Text, FileMode.Create, FileAccess.Write, FileShare.None);
- int bytesSize = 0;
- byte[] downBuffer = new byte[2048];
- while ((bytesSize = strValasz.Read(downBuffer, 0, downBuffer.Length)) > 0)
- {
- strHelyiMentes.Write(downBuffer, 0, bytesSize);
- this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strHelyiMentes.Length, fileSize });
- }
- }
- finally
- {
- strValasz.Close();
- strHelyiMentes.Close();
- }
- }
- }
- private void btnAllj_Click(object sender, EventArgs e)
- {
- webValasz.Close();
- strValasz.Close();
- strHelyiMentes.Close();
- thrLetolt.Abort();
- prgLetolt.Value = 0;
- lblFolyamat.Text = "Letöltés megállítva!";
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement