نمایش نتایج 1 تا 8 از 8

نام تاپیک: گرفتن Progress در BackgroundWorker

  1. #1

    Lightbulb گرفتن Progress در BackgroundWorker

    سلام به همه !
    چطوری میتونم Progress یه بک گراند ورکر را بگیرم؟؟؟
    یا اصن Progress کل فرم را بگیرم؟؟؟
    میخوام یک فایل را با webcilent دانلود کنم!
    webcilent تو یه یکگراند ورکر تعریف شده!
    حالا میخوام اون مقدار از فایلی که دانلود شده یا اون مقدار از عملیات که انجام شده را در قالب 0 تا 100 به پراپرتی Value یه ProgressBar بدم!
    چطوری ین کار را بکنم؟؟؟؟



  2. #2
    کاربر دائمی آواتار juza66
    تاریخ عضویت
    دی 1389
    محل زندگی
    هفت تپه - 7hill
    پست
    798

    نقل قول: گرفتن Progress در BackgroundWorker

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Threading;
    using System.Windows.Forms;
    using System.Xml;

    public class Form1 : Form
    {
    private BackgroundWorker backgroundWorker1;
    private Button dowloadButton;
    private XmlDocument document = null;

    public Form1()
    {
    InitializeComponent();
    }

    private void dowloadButton_Click(object sender, EventArgs e)
    {
    // Start the download operation in the background.
    this.backgroundWorker1.RunWorkerAsync();

    // Disable the button for the duration of the download.
    this.dowloadButton.Enabled = false;

    // Wait for the BackgroundWorker to finish the download.
    while (this.backgroundWorker1.IsBusy)
    {
    // Keep UI messages moving, so the form remains
    // responsive during the asynchronous operation.
    Application.DoEvents();
    }

    // The download is done, so enable the button.
    this.dowloadButton.Enabled = true;
    }

    private void backgroundWorker1_DoWork(
    object sender,
    DoWorkEventArgs e)
    {
    document = new XmlDocument();

    // Replace this file name with a valid file name.
    document.Load(@"http://www.tailspintoys.com/sample.xml");

    // Uncomment the following line to
    // simulate a noticeable latency.
    //Thread.Sleep(5000);
    }

    private void backgroundWorker1_RunWorkerCompleted(
    object sender,
    RunWorkerCompletedEventArgs e)
    {
    if (e.Error == null)
    {
    MessageBox.Show(document.InnerXml, "Download Complete");
    }
    else
    {
    MessageBox.Show(
    "Failed to download file",
    "Download failed",
    MessageBoxButtons.OK,
    MessageBoxIcon.Error );
    }
    }

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
    if (disposing && (components != null))
    {
    components.Dispose();
    }
    base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
    this.dowloadButton = new System.Windows.Forms.Button();
    this.SuspendLayout();
    //
    // backgroundWorker1
    //
    this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
    this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandl er(this.backgroundWorker1_RunWorkerCompleted);
    //
    // dowloadButton
    //
    this.dowloadButton.Location = new System.Drawing.Point(12, 12);
    this.dowloadButton.Name = "dowloadButton";
    this.dowloadButton.Size = new System.Drawing.Size(75, 23);
    this.dowloadButton.TabIndex = 0;
    this.dowloadButton.Text = "Download file";
    this.dowloadButton.UseVisualStyleBackColor = true;
    this.dowloadButton.Click += new System.EventHandler(this.dowloadButton_Click);
    //
    // Form1
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(104, 54);
    this.Controls.Add(this.dowloadButton);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false);

    }

    #endregion
    }

    static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
    }
    }

  3. #3

    نقل قول: گرفتن Progress در BackgroundWorker

    داداش من اینا از کجاش شروع کنم؟؟؟؟
    یه چیزی بگو به گروه خونی ما بخوره!!!

  4. #4
    کاربر دائمی آواتار juza66
    تاریخ عضویت
    دی 1389
    محل زندگی
    هفت تپه - 7hill
    پست
    798

    نقل قول: گرفتن Progress در BackgroundWorker

    نقل قول نوشته شده توسط hosseinghaheri مشاهده تاپیک
    داداش من اینا از کجاش شروع کنم؟؟؟؟
    یه چیزی بگو به گروه خونی ما بخوره!!!

    چه میدونم شما یجور نام تایپیک انتخاب کردید گفتم شاید بدونید

    خوب عیبی نداره این دو تا سایت هستش بصورت خیلی ساده و با مثال پیش رفتن
    http://stackoverflow.com/questions/7...ckgroundworker

    http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx

  5. #5

    نقل قول: گرفتن Progress در BackgroundWorker

    مرسی این بهتر بود !

  6. #6

    نقل قول: گرفتن Progress در BackgroundWorker

    شرمنده دادش ولی توی قسمت
     backgroundWorker1.ProgressChanged += (s, e) =>
    {
    ReportProgress(String.Format("Progress: {0}%", e.ProgressPercentage));
    };

    دو تا ارور گرفت !
    1) ReportProgress را نشناخت ! حالا نمی دونم یوزینگ می خواد ایا؟
    2) به e توی خط اولم گیر داد!
    مشکل چیه؟؟

  7. #7
    محروم شده
    تاریخ عضویت
    بهمن 1391
    محل زندگی
    جنب حرم امام رضا(ع)
    سن
    23
    پست
    1,514

    نقل قول: گرفتن Progress در BackgroundWorker

    نقل قول نوشته شده توسط hosseinghaheri مشاهده تاپیک
    شرمنده دادش ولی توی قسمت
     backgroundWorker1.ProgressChanged += (s, e) =>
    {
    ReportProgress(String.Format("Progress: {0}%", e.ProgressPercentage));
    };

    دو تا ارور گرفت !
    1) ReportProgress را نشناخت ! حالا نمی دونم یوزینگ می خواد ایا؟
    2) به e توی خط اولم گیر داد!
    مشکل چیه؟؟
    گمون کنم اون e مال رویداد خاصی باشه
    البته من BackGroundWorker کار نکردم
    ولی اگه اشتباه نکنم باید در یک رویداد خاصی این کد ها رو بذارید که از E ارور نگیره

  8. #8
    کاربر دائمی آواتار abbas.oveissi
    تاریخ عضویت
    دی 1389
    محل زندگی
    تهران
    پست
    578

    نقل قول: گرفتن Progress در BackgroundWorker

    سلام،در شیء WebClient یدونه رخداد هست به نام DownloadProgressChanged که هر بار تغییر در Progress دریافت انجام بشه،فراخوانی میشود.بعد نیازی به BackgroundWorker نیست و میتونید از متد DownloadFileAsync استفاده کنید.نمونه کد هم در زیر براتون میذارم :
                WebClient webClient = new WebClient();
    webClient.DownloadProgressChanged += (s, ee) =>
    {
    progressBar1.Value = ee.ProgressPercentage;
    };

    webClient.DownloadFileAsync(new Uri("www.example.com/output.dat"), @"f:\Output.dat");


تاپیک های مشابه

  1. سوال: backup گرفتن از دیتابیس همراه با progress bar
    نوشته شده توسط aminhexa در بخش C#‎‎
    پاسخ: 1
    آخرین پست: سه شنبه 15 بهمن 1392, 07:11 صبح
  2. گرفتن فایل پیشتیبان از اکسس
    نوشته شده توسط منصور بزرگمهر در بخش Access
    پاسخ: 1
    آخرین پست: شنبه 20 اسفند 1384, 21:18 عصر
  3. کپی گرفتن از کلیه اشیا یک بانک در یک بانک جدید
    نوشته شده توسط Sadegh_S در بخش Maintenance Plan
    پاسخ: 1
    آخرین پست: جمعه 30 خرداد 1382, 16:58 عصر
  4. پرینت گرفتن datareport
    نوشته شده توسط bahman_bq در بخش VB.NET
    پاسخ: 7
    آخرین پست: شنبه 20 اردیبهشت 1382, 08:30 صبح
  5. database (sql) and progress bar؟
    نوشته شده توسط khafanovich در بخش بانک های اطلاعاتی در Delphi
    پاسخ: 1
    آخرین پست: شنبه 30 فروردین 1382, 19:19 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •