backgroundworker

Is there an alternative to use the Background Worker in WPF?

十年热恋 提交于 2020-01-13 09:38:09
问题 I am a beginner with WPF, in my application I need to perform a series of Initialization steps, these take 10-15 seconds to complete during which my UI becomes unresponsive. I was using yesterday the background worker but it didn't update my window, in fact it was frozen. Not sure, but maybe it didn't work because this control is only for Windows Forms. UPDATE: If not too much trouble, can you post me an example to use the alternative? For my case, the program will get some values from a

Is BackgroundWorker's IsBusy same as “IsAlive”?

人盡茶涼 提交于 2020-01-13 09:27:12
问题 I am trying to figure out a way to verify that a BackgroundWorker thread is alive (i.e. still running. The thread is essentially implemented as a simple infinite loop: while (AllConditionsMet()) { DoSomeMagic(); Thread.Sleep(10000); } The closest thing to IsAlive() I found so far is the IsBusy property, but given that my thread Sleep()s most of the time, I am not sure whether this will do the job. Can I count on IsBusy to do: if (!myWorker.IsBusy) RestartWorker(); or am I calling for trouble?

Easy way to excecute method after a given delay?

放肆的年华 提交于 2020-01-11 19:56:26
问题 Is there a easy way to perform a method after a given delay like in iOS out of the box? On iPhone I would do this: [self performSelector:@selector(connectSensor) withObject:nil afterDelay:2.5]; It will then schedule the method connectSensor on the main thread (UI thread) to be executed after 2,5 seconds. And because it is automatically scheduled on the main thread, you don't have to worry about cross thread issues. (There is also a performSelectorOnBackground version) So how would I do this

“This BackgroundWorker states that it doesn't report progress.” - Why?

别等时光非礼了梦想. 提交于 2020-01-11 19:55:57
问题 i am new to this backgroundworker thing i have read some articles about how to create one this is what it produced private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { Bitmap imgbox = new Bitmap(pictureBox.Image); int imgHeight = imgbox.Height; int imgWidth = imgbox.Width; int counter = 1; MinMaxWidth = imgWidth - 50; MaxWidth = imgWidth; try { Color c; //Color c2; for (int i = 0; i < imgbox.Width; i++) { for (int j = 0; j < imgbox.Height; j++) { c = imgbox.GetPixel(i, j)

Easy way to excecute method after a given delay?

瘦欲@ 提交于 2020-01-11 19:55:34
问题 Is there a easy way to perform a method after a given delay like in iOS out of the box? On iPhone I would do this: [self performSelector:@selector(connectSensor) withObject:nil afterDelay:2.5]; It will then schedule the method connectSensor on the main thread (UI thread) to be executed after 2,5 seconds. And because it is automatically scheduled on the main thread, you don't have to worry about cross thread issues. (There is also a performSelectorOnBackground version) So how would I do this

“This BackgroundWorker states that it doesn't report progress.” - Why?

家住魔仙堡 提交于 2020-01-11 19:55:12
问题 i am new to this backgroundworker thing i have read some articles about how to create one this is what it produced private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { Bitmap imgbox = new Bitmap(pictureBox.Image); int imgHeight = imgbox.Height; int imgWidth = imgbox.Width; int counter = 1; MinMaxWidth = imgWidth - 50; MaxWidth = imgWidth; try { Color c; //Color c2; for (int i = 0; i < imgbox.Width; i++) { for (int j = 0; j < imgbox.Height; j++) { c = imgbox.GetPixel(i, j)

Why can't UI components be accessed from a backgroundworker?

只愿长相守 提交于 2020-01-11 10:23:50
问题 Threads all share resources. That's the whole problem around multi-threaded operations. MSDN says: You must be careful not to manipulate any user-interface objects in your DoWork event >handler. Instead, communicate to the user interface through the ProgressChanged and RunWorkerCompleted events. BackgroundWorker events are not marshaled across AppDomain boundaries. Do not use a BackgroundWorker component to perform multithreaded operations in more than one AppDomain. And yet when I use the

Why can't UI components be accessed from a backgroundworker?

老子叫甜甜 提交于 2020-01-11 10:23:03
问题 Threads all share resources. That's the whole problem around multi-threaded operations. MSDN says: You must be careful not to manipulate any user-interface objects in your DoWork event >handler. Instead, communicate to the user interface through the ProgressChanged and RunWorkerCompleted events. BackgroundWorker events are not marshaled across AppDomain boundaries. Do not use a BackgroundWorker component to perform multithreaded operations in more than one AppDomain. And yet when I use the

Stopping Thread started by backgroundworker

北城以北 提交于 2020-01-11 09:47:22
问题 I have a windows form which utilizes a backgroundworker. The backgroundworker instantiates an object and then executes a method in that object. My problem is that when I use backgroundworker.CancelAsync the method running on the remote object does not stop. In the example below, the dowork method continues to execute after button cancel is clicked. FYI, dowork is looping thru a spreadsheet and doing some data manipulation based on the rows in the spreadsheet. private void backgroundWorker1

How to use the BackgroundWorker event RunWorkerCompleted

隐身守侯 提交于 2020-01-11 08:27:08
问题 All,I already knew the basic usage the BackgroundWorker to handle multiple thread case in the WinForm . And the code structure looks like below. In the main thread of application. just start the BackgroundWork. if (backgroundWorker1.IsBusy != true) { // Start the asynchronous operation. backgroundWorker1.RunWorkerAsync(); } Then it would fire the DoWork event . So we can do something in there. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker =