backgroundworker

How to wait for a BackgroundWorker to cancel?

主宰稳场 提交于 2019-12-17 02:27:19
问题 Consider a hypothetical method of an object that does stuff for you: public class DoesStuff { BackgroundWorker _worker = new BackgroundWorker(); ... public void CancelDoingStuff() { _worker.CancelAsync(); //todo: Figure out a way to wait for BackgroundWorker to be cancelled. } } How can one wait for a BackgroundWorker to be done? In the past people have tried: while (_worker.IsBusy) { Sleep(100); } But this deadlocks, because IsBusy is not cleared until after the RunWorkerCompleted event is

Background Worker Updating from a different class (preferably via events)

烂漫一生 提交于 2019-12-14 03:53:27
问题 I have a background worker in my GUI class. private void bw_DoWork(object sender, DoWorkEventArgs e) { ProgressClass obj = new ProgressClass(); Importer tradeImporter = e.Argument as Importer; BackgroundWorker worker = sender as BackgroundWorker; List<TradeUploadInfo> list = obj.AllocateTrades2(tradeImporter, false); e.Result = list; //Passes the list for processing } Importer is my own class. Now, the AllocateTrades2 method has all the processing done in it. My question is, how would I go

WPF C# application will freeze my whole computer ever 2-3 times I run it

拥有回忆 提交于 2019-12-14 03:46:16
问题 I put a lot of information in this issue because I have no idea what will be relavent Issue: I am having an issue with a program I am working on where when running it, it will freeze my whole computer and return no error (I am completely incapable of doing anything CTRL+ALT+DEL doesn't even work). This program accepts a connection from a android client and atm the android client is not configured correctly so the connection is being rejected. Question: How can I stop my program from freezing

Add controls to a StackPanel in a BackgroundWorker or async Task called from another BackgroundWorker

痞子三分冷 提交于 2019-12-14 03:36:54
问题 I'm coding an IRC Client, using Meebey SmartIrc4Net. By using a BackgroundWorker, i listen to all IRC events by the .Listen() method provided by the class. There's an OnJoin event which i handle with a method, this method gets the user list of the channel by spawning another BackgroundWorker and polling for the data in it. So now i have a Main thread, an irc event bgWorker which to my knowledge is a child of the Main thread, and a user list bgWorker. The problem is that i cannot create UI

SqlDependency using BackgroundWorker

末鹿安然 提交于 2019-12-14 03:09:13
问题 I have a table in a SQL Server database that represents a log file of some actions inserted from a running windows service. Everything is working well. But, I have a Windows application that gets the latest rows that have been inserted in the log table and views it in a DataGridView . While developing this application I depended on Using SqlDependency in a Windows Application from MSDN. It is working well, but when the log table receives a large number of log details, the Windows app hangs up

What type/types of threading should I use in WPF and c# for my scenario… regular threads, background worker, or thread pool?

落爺英雄遲暮 提交于 2019-12-14 02:27:18
问题 I have an order manager application created in C# and WPF. The order manager application needs to communicate back and forth with a shipping application that is written in a completely different shipping language. The method of communication between the programs is an XML file whose EnableShipping attribute is either a 0 or a 1 and a SQL database. In my order manager application I have button that "Begins shipping" and changes the EnableShipping attribute from a 0 to a 1. The shipping

How can I wait on a BackgroundWorker's completion?

梦想的初衷 提交于 2019-12-13 19:11:29
问题 I would like to use the BackgroundWorker to perform a database transaction from a GUI. How can I command the BackgroundWorker to perform the work and then WAIT for the worker to complete while keeping the GUI responsive? Do I have to use DoEvents for this purpose, or is there another way? 回答1: Asking "How can I command the BackgroundWorker to perform the work and then WAIT for the worker to complete while keeping the GUI responsive?" is really asking "How do I use the BackgroundWorker ?".

ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#

本秂侑毒 提交于 2019-12-13 16:38:07
问题 I'm new to C#, RestSharp, and threading, so heres what I'm trying to do: I have made a program that will allow me to upload photos to tumblr, and I have the uploading working so far. Now I need the stop button to work, which I believe means I must use ExecuteAsync() instead of Execute() . I also have my code put in a backgroundworker, like this: private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (backgroundWorker1.CancellationPending) { e.Cancel = true; MessageBox

Backgroundworker abort

跟風遠走 提交于 2019-12-13 12:01:19
问题 I recently tried to use backgroundworker instead of "classic" threads and I'm realizing that it's causing, at least for me, more problems than solutions. I have a backgroundworker running a synchronous read (in this case from serialPort) and getting blocked around 30 seconds in 1 code line, then cancellationpending isn't the solution. I'm seeing that if the application gets closed at this point (either with the cross button and Application.Exit()) the process keeps zombie forever. I need a

BackgroundWorker not Running when it's needed

主宰稳场 提交于 2019-12-13 10:31:36
问题 I am writing a program which lets users upload a large file, compare it to another large file uploaded before and return a list of new entries and discontinued entries. This requires the program to run a few queries, so it takes a while for the program to complete the task. Of course, this means that until the program is done with the task, the user cannot do anything else. To prevent that from happening I have included a BackgroundWorker to the project. The problem is, the BackgroundWorker