backgroundworker

BackgroundWorker - CancellationPending changing to false in RunWorkerCompleted. Why?

坚强是说给别人听的谎言 提交于 2019-12-10 15:59:12
问题 After canceling the BackGroundWorker, in the DoWork, the CancellationPending is true but when he comes to the RunWorkerCompleted, the CancellationPending is false. I dont know what did I do wrong? static BackgroundWorker b1; static void Main(string[] args) { b1=new BackgroundWorker(); b1.DoWork += new DoWorkEventHandler(work1); b1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completed); b1.WorkerSupportsCancellation = true; b1.RunWorkerAsync("Hellow"); Console.ReadLine(); }

Closing the form when backgroundWorker stops working

孤街醉人 提交于 2019-12-10 15:35:20
问题 I'm working on an application that should read the data from Mifare smart card. I have to create a form will check the Mifare reader periodically and when the card is in range, read its serial number and send it to the parent form. I managed to get the background worker to read the serial number, but I can't close the form from it due to cross thread calling error it would cause. Is there a way to monitor the work that backGroundWorker does, and when it successfully reads the card ID, to stop

Sharing objects between a BackgroundWorker and main thread

落爺英雄遲暮 提交于 2019-12-10 14:58:22
问题 I have a ListBox object in my main thread (WPF application). Why am I not able to access it in BackgroundWorker thread. As far as I know, the stack is separate for each thread, but the heap is common. Isn't ListBox object created in heap. In that case why is it not accessible. I tried passing the ListBox reference as parameter and tried to access its contents in the BackgroundWorker. Is the concept of sharing objects between threads different from C++? 回答1: Like WinForms, the design of WPF is

Is BackgroundWorker the only way to keep a WCF/WPF application responsive?

こ雲淡風輕ζ 提交于 2019-12-10 14:15:13
问题 Client/server desktop application using C#, WCF, WPF. Since pretty much every action is going to require a trip to the server (list/create/save/delete/etc), every action has the potential to freeze the entire UI. Here's an example of a naive implementation with a call to service.GetAll() which could take a "long" time (more than a few hundred milliseconds): private void btnRefresh_Click(object sender, RoutedEventArgs e) { vm.Users.Clear(); foreach (var user in service.GetAllUsers()) vm.Users

Is there no simple way to set WPF StatusBar text?

时光怂恿深爱的人放手 提交于 2019-12-10 12:11:46
问题 I want to set the Text of a TextBlock in my StatusBar before making the user wait for a short moment while my program does a little bit of work. Aparently, instead of doing a nice little function like this (which does not work): Function Load(ByVal Id As Guid) As Thing Cursor = Cursors.Wait TextBlockStatus.Text = "Loading..." TextBlockStatus.UpdateLayout() Dim Found = From t In db.Thing _ Where t.Id = Id _ Select t TextBlockStatus.Text = String.Empty Cursor = Cursors.Arrow Return Found End

C# question on preventing GUI from becoming sluggish when using backgroundworker/thread

℡╲_俬逩灬. 提交于 2019-12-10 12:11:17
问题 I am trying to build a small application that logins into a server and gathers data from it constantly. The problem that I am having is that my GUI is slow to respond even when using either background worker or a thread. When my application tries to login into the server, I see "(Not Responding)" appear in my login form, but it logins in few seconds later without Windows giving the "The program has stopped responding... terminate application" dialog. When I click the start button on my

How can I use one BackgroundWorker to do different activities?

北战南征 提交于 2019-12-10 11:45:09
问题 I am programming using VB.NET 2005. I am using a BackgroundWorker to load a large list or text file and process it. Is it possible to use the same background worker to process something else, i.e. to process the text file that was loaded? somthing like Dim bwkMain as New BackgroundWorker() If its possible, how do I implement it in the same form as I have already implemented for the first one? EDIT The question is: is it possible to use the same BackgroundWorker for another task, after it

c# Background worker class

╄→гoц情女王★ 提交于 2019-12-10 11:33:36
问题 I want to put this method into background worker class, i am trying but stuck, can any one help me how to run this method into background worker class: I am calling this method into my asp.net page, where file are zipped on server and then returend to the client. but zipping of file may take longer and user will see a busy screen, so to avoid that i want to use background worker class: [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)] public string Zip(string f, bool original) {

Thread not run immediately when using more than 4 BackgroundWorker

牧云@^-^@ 提交于 2019-12-10 11:23:50
问题 I use multiple BackgroundWorker control to run some task as multithreading. But I found that when using more than 4 BackgroundWoker, the one from 4th forward delay more than second to actually execute from when calling RunWorkerAsync . Could help me how can I start all backgroundworker immediately? class TaskLog { public int task_id; public DateTime call_time; public DateTime start_time; public DateTime end_time; } BackgroundWorker[] bws = new BackgroundWorker[18]; int[] tasks = new int[] { 1

Configure Autofac Container for background thread

ε祈祈猫儿з 提交于 2019-12-10 10:35:20
问题 I have an asp.net MVC site which has many components registered using an InstancePerHttpRequest scope, however I also have a "background task" which will run every few hours which will not have an httpcontext. I would like to get an instance of my IRepository which has been registered like this builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)) .InstancePerHttpRequest(); How do I do this from a non http context using Autofac? I think the IRepository should use the