backgroundworker

How to update GUI with backgroundworker?

五迷三道 提交于 2019-11-26 01:47:25
问题 I have spent the whole day trying to make my application use threads but with no luck. I have read much documentation about it and I still get lots of errors, so I hope you can help me. I have one big time consuming method which calls the database and updates the GUI. This has to happen all the time(or about every 30 seconds). public class UpdateController { private UserController _userController; public UpdateController(LoginController loginController, UserController userController) {

How to update GUI with backgroundworker?

左心房为你撑大大i 提交于 2019-11-26 01:29:44
I have spent the whole day trying to make my application use threads but with no luck. I have read much documentation about it and I still get lots of errors, so I hope you can help me. I have one big time consuming method which calls the database and updates the GUI. This has to happen all the time(or about every 30 seconds). public class UpdateController { private UserController _userController; public UpdateController(LoginController loginController, UserController userController) { _userController = userController; loginController.LoginEvent += Update; } public void Update() {

How to use WPF Background Worker

回眸只為那壹抹淺笑 提交于 2019-11-26 01:22:41
问题 In my application I need to perform a series of initialization steps, these take 7-8 seconds to complete during which my UI becomes unresponsive. To resolve this I perform the initialization in a separate thread: public void Initialization() { Thread initThread = new Thread(new ThreadStart(InitializationThread)); initThread.Start(); } public void InitializationThread() { outputMessage(\"Initializing...\"); //DO INITIALIZATION outputMessage(\"Initialization Complete\"); } I have read a few

BackgroundWorker vs background Thread

隐身守侯 提交于 2019-11-26 00:39:30
问题 I have a stylistic question about the choice of background thread implementation I should use on a windows form app. Currently I have a BackgroundWorker on a form that has an infinite (while(true)) loop. In this loop I use WaitHandle.WaitAny to keep the thread snoozing until something of interest happens. One of the event handles I wait on is a \" StopThread \" event so that I can break out of the loop. This event is signaled when from my overridden Form.Dispose() . I read somewhere that

How to use a BackgroundWorker?

Deadly 提交于 2019-11-25 23:22:01
问题 I know it has 3 methods. In my program I have a method to send a message. It is often late and the program sometimes doesn\'t send the message at all in response to a button press. At times it is as late as 5 seconds from what I would expect and the program freezes. I want to use a BackgroundWorker to send the message as expected and allow the program to run normally at all times. I had the code for sending the message in a button handler. Now where do I put this equivalent code? I would like

The calling thread cannot access this object because a different thread owns it

青春壹個敷衍的年華 提交于 2019-11-25 22:21:43
问题 My code is as below public CountryStandards() { InitializeComponent(); try { FillPageControls(); } catch (Exception ex) { MessageBox.Show(ex.Message, \"Country Standards\", MessageBoxButton.OK, MessageBoxImage.Error); } } /// <summary> /// Fills the page controls. /// </summary> private void FillPageControls() { popUpProgressBar.IsOpen = true; lblProgress.Content = \"Loading. Please wait...\"; progress.IsIndeterminate = true; worker = new BackgroundWorker(); worker.DoWork += new System

How to stop BackgroundWorker on Form&#39;s Closing event?

岁酱吖の 提交于 2019-11-25 22:21:09
问题 I have a form that spawns a BackgroundWorker, that should update form\'s own textbox (on main thread), hence Invoke((Action) (...)); call. If in HandleClosingEvent I just do bgWorker.CancelAsync() then I get ObjectDisposedException on Invoke(...) call, understandably. But if I sit in HandleClosingEvent and wait for bgWorker to be done, than .Invoke(...) never returns, also understandably. Any ideas how do I close this app without getting the exception, or the deadlock? Following are 3