Note that there are some explanatory texts on larger screens.

plurals
  1. POMulti BackgroundWorker
    text
    copied!<p>I have a program with Multi BackgroundWorker. I have 2 question:<br></p> <ol> <li><p>Is It easy to the computer to create 1000 or more BackgroundWorker instance at once??<br> If not, what can I do instead??</p></li> <li><p>In the program I show the program process in a textBox. but it doesn't show immediately on the UI, just after some minutes it show all at once. It can be from 2 reasons:</p> <ol> <li>The invoke() doesn't work correctly.</li> <li>The new ProgressChangedEventHandler(ProgressChanged) doesn't work correctly. </li> </ol></li> </ol> <p><b>My code:</b></p> <p>Main code:</p> <pre><code>worker = new BackgroundWorker[dtPP.Rows.Count]; for (int i = 0; i &lt; dtPP.Rows.Count - 1; i++) { worker[i] = new BackgroundWorker { WorkerReportsProgress = true }; worker[i].DoWork += new DoWorkEventHandler(DoWork); worker[i].ProgressChanged += new ProgressChangedEventHandler(ProgressChanged); worker[i].RunWorkerAsync(i); Thread.Sleep(1000); } </code></pre> <p>Func of worker:</p> <pre><code> void ProgressChanged(object sender, ProgressChangedEventArgs e) { Console.WriteLine(msg); } void DoWork(object sender, DoWorkEventArgs e) { string st; int i=(int)e.Argument; try { ((BackgroundWorker)worker[i]).ReportProgress(i*-1); httpDownload = new HttpDownloader(dtPP.Rows[(int)e.Argument]["pp_url"].ToString()); htmlDoc = httpDownload.GetPage(); htmlDoc = Pharsing.CreateCorrectHtmlDoc(htmlDoc); st = htmlDoc != "" ? "OK" : "Error"; ((BackgroundWorker)worker[i]).ReportProgress(i); } catch (WebException ex) { st = ex.Status.ToString(); } } </code></pre> <p>This is a class that all text in Console.WriteLine("") insert to textBox that is in the Form, because I have a winApplication program. </p> <pre><code> class cl : TextWriter { TextBox _output = null; public cl(TextBox output) { _output = output; } public override void Write(char value) { base.Write(value); _output.Invoke(new WriteDeligate(this.WriteDel), value); } public override Encoding Encoding { get { return System.Text.Encoding.UTF8; } } void WriteDel(char value) { _output.AppendText(value.ToString()); // When character data is written, append it to the text box. } public delegate void WriteDeligate(char value); } </code></pre> <p>p.s. The program create BackgroundWorker instance for each url that I want to download. and that I begin to download all the pages at almost once.</p> <p>Thank, Chani</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload