backgroundworker

Background Worker Thread Problem

回眸只為那壹抹淺笑 提交于 2019-12-11 04:44:30
问题 I am using background worker in my Application my code for this void CreateThreadForEachServer() { DataAccess oDA = new DataAccess(); List<Server> allServerData = oDA.GetAllServers(); foreach (Server serverData in allServerData) { backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork); backgroundWorker.RunWorkerAsync(serverData); } } void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Server server = (Server)e

InvalidOperationException when trying to access a complex object from another thread

旧时模样 提交于 2019-12-11 03:36:20
问题 After I tried lots and lots of solutions I couldn't solve this problem by any means so I started to believe that there is no solution for this problem. I have an object that contains complex attributes. E.g: List<SomeComplexObject> . I am running a method from this class on a worker thread to keep the GUI running until the worker thread finishes. When it finishes execution, I want to use the attributes of these objects to update GUI let's say I want to use List<SomeComplexObject> looping

Asynchronous Writes To Textbox in C# are Overwritten

早过忘川 提交于 2019-12-11 02:50:31
问题 I have an application wherein two threads write asynchronously to a single textbox. It works, except that the second thread to write to the textbox overwrites the line that the first thread just wrote. Any thoughts or insight into the problem would be greatly appreciated. I am using Microsoft Visual C# 2008 Express Edition. Thanks. delegate void SetTextCallback(string text); private void SetText(string text) { this.textBox1.Text += text; this.textBox1.Select(textBox1.Text.Length, 0); this

Can't get items in a ListView cross-thread

泄露秘密 提交于 2019-12-11 02:45:16
问题 My background worker needs to iterate through each item in a ListView. However I can't do this: foreach (ListViewItem Item in List.Items) because it's a cross thread operation. I also can't put the items in a ListView.ListViewItemCollection and make the background worker read from that. This is still trying to access the ListView and creating a cross thread operation. How can I make the ListView's items available to the background worker without putting them in a variable somewhere? 回答1: Try

Does cron job block the main process or nodejs will create a worker to do cron task

烈酒焚心 提交于 2019-12-11 02:39:42
问题 I am using node-cron to do some heavy tasks (update database) every minute. Does this task use main process to work or nodejs will create some workers to do these taks? var CronJob = require('cron').CronJob; new CronJob('0 * * * * *', function() { //Update database every minute here console.log('Update database every minute'); }, null, true, 'America/Los_Angeles'); 回答1: It is supposed to create a worker for you.. It is not well documented in the library docs but: 1) You can see at the

AsyncCallback to BackgroundWorker

为君一笑 提交于 2019-12-11 02:33:32
问题 I want to use the .NET-FTP Libary (http://netftp.codeplex.com). The libary offers BeginOpenRead(string,AsyncCallback,object) to download the contents using the Asynchronous Programming Model. My implementation of the Callback is basically the same as the example: static void BeginOpenReadCallback(IAsyncResult ar) { FtpClient conn = ar.AsyncState as FtpClient; try { if (conn == null) throw new InvalidOperationException("The FtpControlConnection object is null!"); using (Stream istream = conn

WMPLib often stops playing

走远了吗. 提交于 2019-12-11 02:07:26
问题 I play mp3s and m4as with the following method: private void playmp3(string path) { WMPLib.WindowsMediaPlayer a = new WMPLib.WindowsMediaPlayer(); a.URL = path; a.controls.play(); } Usually when I play them, they only play for around 5 seconds or less and then stop playing. If i interact with the (WPF) form in any way, it also stops. I call playmp3 from a BackgroundWorker . Edit: It actually stops playing about a tenth of a second after I move my mouse. 回答1: You need to also code in the

How to run batched WCF service calls in Silverlight BackgroundWorker

北战南征 提交于 2019-12-11 01:55:21
问题 Is there any existing plumbing to run WCF calls in batches in a BackgroundWorker? Obviously since all Silverlight WCF calls are async - if I run them all in a backgroundworker they will all return instantly. I just don't want to implement a nasty hack if theres a nice way to run service calls and collect the results. Doesnt matter what order they are done in All operations are independent I'd like to have no more than 5 items running at once Edit : i've also noticed (when using Fiddler) that

C#, Updating a Progress Bar Using Background Worker From a Different Class

谁说我不能喝 提交于 2019-12-11 01:08:21
问题 I am attempting to update the progress bar on a main form with the work being done in a different class. For example: private void transfer_Click(object sender, EventArgs e) { Guid aspnetUserId = Guid.Parse(System.Configuration.ConfigurationSettings.AppSettings["ASPNetUserID"]); WC1toWC2Transfer transfer = new WC1toWC2Transfer(aspnetUserId); backgroundWorker1.RunWorkerAsync(transfer); } And then in the background method actually call the method: private void backgroundWorker1_DoWork(object

The RunWorkerCompleted is triggered before the progressbar reaches 100% [duplicate]

心不动则不痛 提交于 2019-12-11 00:07:49
问题 This question already has answers here : Disabling .NET progressbar animation when changing value? (5 answers) Closed 3 years ago . I'm doing my first WinForms application featuring a background worker and progress bar. When I run my code it looks like the progress bar is delayed, because its animation -- approaching 100% -- is not completed when the code for the RunWorkerCompleted is executed. (A few hundred milliseconds the progress bar is filled.) Is there a way to make things more