BackgroundWorker starting again in Completed event

I want a background worker to continue running and occasionally update the user interface. My first idea was to use a BackgroundWorker and in its completed event just fire it up again.
Is using a BackgroundWorker in this fashion acceptable? Or are there potential issues from using the completed event to trigger the worker?
Below is some Pseudo code of what my intentions are
class Program
private static BackgroundWorker worker;
private static Int32 runs = 0;
static void Main(string[] args)
worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
worker.RunWorkerAsync(runs);
Console.ReadLine();
static void worker_DoWork(object sender, DoWorkEventArgs e)
//Do time consuming work
Thread.Sleep(3000);
static void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
//Update the UI and start time consuming work again
runs++;
Console.WriteLine("Completed run #" + runs);
worker.RunWorkerAsync();

Assuming you are doing something that must always be done in the background while your app is running, like monitoring a file location or pinging a host, what you suggest, as well as the other answers, is actually a really bad idea. Creating and destroying
a thread is not a free operation... there are costs associated with that and repeatedly doing it will incur a performance penalty. Timers and Tasks are just fancy wrappers for threads so those suggestions are just putting a different colored lipstick on the
same pig.
You are doing the right thing by using a background worker... that is what they are designed for... but instead of killing the thread and restarting it, DoWork should remain in a loop checking to see if the thread has been cancelled while using the ReportProgress
event whenever there is something to report to the UI. Whenever your thread raises that event, you can catch it in the ProgressChanged event handler and update the UI for your user. This way the thread never gets shut down and is always doing its job tossing
up notices when there is something to note.
When your app shuts down or you are done monitoring, just cancel the thread. Background workers support that if you set WorkerSupportsCancellation = true when you create the worker and then call CancelAsync to cancel the thread. Again, be sure to check within
the loop to see if the thread has been cancelled to see if you need to break out and end the DoWork method. Make sure that the thread isn't too busy doing something long running that it becomes unresponsive to the cancellation call (i.e. some sort of really
long blocking call).
The MSDN docs have an example here: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker%28v=vs.110%29.aspx

Similar Messages

  • I need to make a pdf document, made in photoshop, 'page turn' and then add it to my website. I know I can do this in indesign but indesign will not open pdf files for some inexplicable reason. Any ideas how I can do it without completely starting again?

    I need to make a pdf document, already made in photoshop, 'page turn' and then add it to my website as an e-brochure. I know I can do this in indesign but indesign will not open pdf files for some inexplicable reason. Any ideas how I can do it without completely starting again?

    Hello waitingone,
    please try this (all terms are translated from my German programs to my best knowledge):
    1. Did the creator of the pdf file enable the import options?
    2. See import options: choose an other visibility option for your layer.
    3. Let you show the import options and click into one with a black background and try these out (often a gray is selected).
    4. See trimming: try the different modes there. Often works: "Media".
    5. Is the pdf file (eg from Word) correctly created?
    6. Is the PDF file protected? >>> no import possible.
    7. If that does not help, store the pdf file in Acrobat, repair possible errors, run the PDF Optimizer before placing in InDesign.
    Good luck!
    Hans-Günter

  • I got a new iPad last month and set up through iCloud. Still have a message on my screen that it is still restoring from iCloud. How do I get it to complete other than having to rest me start again?

    I Got a new iPad last month and sent up in the usually way and syncd to iCloud. However it has ever since shown a comment saying:
    Restoring from from I cloud backup
    i I have no idea how to get it to complete. Or do I need to re-set and start again?
    Help!

    Where do you see this message? I know it can take a few hours to restore from an iCloud backup if you had lots of apps, data, movies, camera roll photos etc on it, but it should not take days and daus to finish.
    Have you restarted or reset your iPad since you got it? Not the reset that you are talking about - I mean the system reset. Try either or both and see if the message goes away.
    Restart or reset your iPhone, iPad, or iPod touch - Apple Support

  • I was recently prompted to update iPhoto and make changes to the library.  I did it but it keeps hanging up in step 5 or 6 and won't complete the cycle.  I have used force quit, rebooted and started again several times.  How do i get this to work?

    I was recently prompted to update iPhoto and make changes to the library.  I did it but it keeps hanging up in step 5 or 6 and won't complete the cycle.  I have used force quit, rebooted and started again several times.  How do i get this to work?

    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild.
    If that fails:
    Restore from your back up, repair the Library and try again.

  • So many problems. I need to completely wipe and start again. How?

    I cannot log into my bank but can on other computers or another browser. Google earth won't work. I want to completely de install Firefox and start again but when I try it reloads all my settings with all the same problems. Refreshing did not work either. How do I get rid of all the settings as if I've never had Firefox and start from scratch?

    See https://www.ssllabs.com/ssltest/analyze.html?d=my.if.com&s=195.171.220.120
    This server uses SSL 3, which is obsolete and insecure. Also it does not negotiate TLS 1.0 or 1.1 cipher suites, even though it would support them.
    You should talk to your bank and ask them, why they use such an insecure server for their online banking.
    Other modern browsers seem to have the same problem.
    You may try with older versions of IE, e.g. IE10, but keep in mind, SSL isn't considered secure anymore.
    https://developer.mozilla.org/en-US/Firefox/Releases/34/Site_Compatibility#Security
    https://blog.mozilla.org/security/2014/10/14/the-poodle-attack-and-the-end-of-ssl-3-0/

  • I've just downloaded Sophos (yesterday) and commenced the scan. It keeps stopping part way through, the 2nd time when it was about 98% completed after 4 hours!!!! I've had to start again. What could be causing this? I have Mountain Lion.

    I've just downloaded Sophos (yesterday) and commenced the scan. It keeps stopping part way through, the 2nd time when it was about 98% completed after 4 hours!!!! I've had to start again. What could be causing this? I have Mountain Lion.

    Thomas A Reed wrote:
    You will be advised by people here that Sophos is "junk" and should be removed {...} Sophos actually works pretty well, in my testing, and so I would suspect that there may be an underlying problem with your file system that needs to be repaired.
    FWIW, I have used Sophos regularly for several years now (including on my new iMac running Mountain Lion versions 10.8.2 & now 10.8.3) & never had any problems with it on any of the half dozen or so Macs I have installed it on.
    Quite a few people automatically assume all Mac A-V software is troublesome junk, & many will leap to the conclusion it is the cause of some problem without considering other potential (& often much more likely) causes, regardless of which A-V product is installed.
    Obviously I hope, not all A-V products are alike, so it doesn't make a lot of sense to me to condemn them all because of problems with one of them. Regarding Sophos in particular, finding first hand reports of it causing problems is quite difficult -- typically, if you ask for the details it turns out to be a second or third hand report & there isn't enough info available to know for certain if it is the real cause or not.
    This is not to say it is impossible for it to cause problems, just that it is prudent to consider all the possibilities before concluding that any one of them is the cause.

  • HT4623 im updating my iOS 6 then my battery completely drain when i re charged my battery my i phone 4 wont start again.

    im updating my iOS 6 then my battery completely drain when i re charged my battery my i phone 4 wont start again.

    I had the same problem updating to the new ios 6. It seem to have removed all my software and everything else from the iphone. It will not operate anymore...does anyone else have this problem? it just happen last night and now all i have is a sign on the iphone asking me to plug it into itunes ....when i do it tells me to restore it. I done this 3 times still the same results. frustrated

  • Im up dating my i phone to iOS 6 then my baterry completely drain i forget to plug my charger,when i re charged my battery for 12 hrs my i phone wont start again i try to conect to my computer but it cant be read also.pls help

    im up dating my i phone to iOS 6 then my baterry completely drain i forget to plug my charger,when i re charged my battery for 12 hrs my i phone wont start again i try to conect to my computer but it cant be read also.pls help

    Thanks too all the people who responded. . . . (noone)
    Got it sorted though. Seems that Apple has issues with multiple apple id's.
    Seems i had to somehow remember and use the original id i had when i first bought my 1st iPhone. . . .
    Even after that it was extremely hard to get my apps back on my PC.
    If anyone else has the same problem. . . .email Apple. Cya.

  • I have bought film, and now I cannot load it. Loading is completed, then I see a message about checking (?), and then the loading starts again. I need help:(

    I have bought a  film, and now I cannot load it. Loading is completed, then I see a message about processing (?), and then the loading starts again. I need help:(

    Thank you so much, Brennen!!!!!! I have downloaded this film after rebooting iPad and after deleting film and re-loading it!!!!!

  • Updating to FF 4 yesterday completely wiped out my entire browsing history -- and started again from scratch as of yesterday. This is an extremely alarming, disappointing, upsetting discovery!!! Is there any way to restore / recover what was lost?

    I went to "History" & found EVERYTHING wiped out & started again from scratch after d/loading new FF version. Most people are rabid about CLEARING History, but I use mine extensively. Finding it gone was not welcome. Any way to fix / recover this?

    I had this problem but when downgrading from FF4 to FF3.6. I was able to recover everything, so maybe the solution is the same.
    [[Profiles|Find your profile folder...]]<br/>
    Close FF
    If there is a file called places.sqlite.corrupt:<br/>
    Rename places.sqlite to places.sqlite.old<br/>
    Rename places.sqlite.corrupt to places.sqlite<br/>
    Restart FF
    And if there isn't well...sorry =/. You might want to save these files elsewhere too just in case before renaming them so they can be replaced.

  • I upgraded from 3.6.13 to Beta 4.0 and now Firefox will not open at all I tried to uninstall to start again but it will not uninstall either it does nothing.

    I uninstalled Beta 4 and re-installed 3.6.13 now Firefox will not open at all I tried to uninstall to start again but it will not uninstall either it does nothing, I have been using Firefox for a long time but cannot resolve this problem can anyone help and give me a solution please. As I use Firefox as my web browser it is very frustrating.
    The fact it will not uninstall appears to be something completely new as nobody I know who uses Firefox has ever encountered this in the past.

    Did you check your security software (firewall)?
    A possible cause is security software (firewall) that blocks or restricts Firefox without informing you about that, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process.
    See [[Server not found]] and [[Firewalls]] and http://kb.mozillazine.org/Firewalls
    If necessary then also see:
    * http://kb.mozillazine.org/Browser_will_not_start_up
    * http://kb.mozillazine.org/Error_loading_websites

  • My Macbook Pro has a black screen when running in Bootcamp Windows 7. Since I updated the mac side my windows side now starts up with completely black screen - no prompt, nothing, Cap keys still light up as does mouse and DVD drive seems to run.

    My Macbook Pro has a black screen when running in Bootcamp Windows 7. Since I updated the mac side my windows side now starts up with completely black screen - no prompt, nothing, Cap keys still light up as does mouse and DVD drive seems to run.
    Will not show up in safe mode, will not show when started from Windows 7 DVD.
    I suspect the Mac update wiped out my PC video drivers but can not think of a way to re-install?
    Can see the PC volume from Mac side with files.
    I've looked at all the online solutions so far and have tried most of them without success. Please help!
    Specs:
    2009 Macbook Pro, 3.06 GHz Intel 2 core, Max 10.6.8.
      Model Name:          MacBook Pro
      Model Identifier:          MacBookPro5,2
      Processor Name:          Intel Core 2 Duo
      Processor Speed:          3.06 GHz
      Number Of Processors:          1
      Total Number Of Cores:          2
      L2 Cache:          6 MB
      Memory:          4 GB
      Bus Speed:          1.07 GHz
      Boot ROM Version:          MBP52.008E.B05
      SMC Version (system):          1.42f4
      Serial Number (system):          7302300GANE
      Hardware UUID:          B2D4B4B4-CD92-5C7A-BDC2-527D30DD8DF3
      Sudden Motion Sensor:
      State:          Enabled

    EDIT: RESOLVED
    For anyone else who finds their way here like I did, this link did it for me: https://forums.geforce.com/default/topic/527599/windows-8-issues-solved-please-r ead-if-you-39-re-having-black-screen-and-or-flickering-/
    Specifically, the posts by Dunsany and valkyr did the trick.  I booted in safe mode, uninstalled and deleted the Nvidia driver, disabled automatic driver installation, and restarted normally.  I then manually downloaded and installed the previous Nvidia driver for my graphics card (which at the time of this writing was 335.23, rather than the latest which was 337.88), and everything is now bueno!
    Two hiccoughs along the way: First, when I tried to uninstall the Nvidia driver the first time, when I restarted I got the login screen (which was a good sign), but it quickly went black again.  I powered down, restarted in safe mode again, and repeated the uninstallation process, and it worked the second time.  Second, when I started the manual install of the 335.23 driver, the computer played a sound similar to the one for disconnecting a USB device, and the screen went black.  I'd seen a lot about trying to increase the brightness (though it hadn't worked up to this point; but if you haven't tried it yet, might as well); I tried it, and it worked! So far I'm back up and running. [/fingers crossed]
    Hope this helps someone else!

  • Have a mac book pro that crashed. ran disk utility to repair. comp booted and ran for short time. then crashed. ran repair again. disk utility said it could not repair files and i needed to format hard drive and start again. now nothing works

    have a mac book pro that crashed. ran disk utility to repair. comp booted and ran for short time. then crashed. ran repair again. disk utility said it could not repair disk and needed to format and start again.
    comp said it could not unmount disk and now when comp trys to boot all i get is a question mark on the screen. help

    Erase and Install
    1. Boot from your Snow Leopard Installer Disc. After the installer loads select your language and click on the Continue button.  When the menu bar appears select Disk Utility from the Utilities menu.
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area.  If it does not say "Verified" then the drive is failing or has failed and will need replacing.  SMART info will not be reported  on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Click on the Options button, set the partition scheme to GUID then click on the OK button. Set the format type to Mac OS Extended (Journaled.) Click on the Partition button and wait until the process has completed.
    4. Quit DU after formatting completes and return to the installer. Install Snow Leopard.
    5. After restart into Snow Leopard download and install Mac OS X 10.6.8 Update Combo v1.1.

  • How do I revert to original footage in Final Cut Pro X version 10.0.9, for some reason I have lost some audio in my timeline and would like to start again but cannot get the original footage?

    How do I revert to original footage in Final Cut Pro X version 10.0.9?
    For some reason I have lost some audio in my timeline and would like to start again but cannot get the original footage?
    Only the edited version which is no good without the audio?
    Please  Help

    What format is your problem clip? Are there wave forms visible in the section without sound?
    Right click on the clip in the event broswer and choose Reveal in Finder; open the clip in Quick Time to confirm that there is sound throughout at that stage of your workflow.
    Russ

  • Premiere cc 2014 crash with message "Adobe Premiere Pro could not find any capable video play modules. Please update your video display drivers and start again."

    I updated to Premiere Pro CC 2014, all the other Adobe CC 2014 software works great, but Premiere doesnt even load. The starting page (frame) comes up - my whole computer slows down and after a minute or two it crashes completely and comes up with the message :  "Adobe Premiere Pro could not find any capable video play modules. Please update your video display drivers and start again."
    I'm running a macbook Pro 15" (2014) with 16GB RAM and 760GB SSD.
    PLEASE HELP!

    Hi Delarey,
    Please go to the following location and rename the folder to old_folder name
    User/user  library/Application Support and rename Adobe folder
    User/user library/Preferences and rename the Adobe folder
    Then go to Documents folder and Go to Adobe/Premiere pro/8.0 and rename 8.0 folder
    Make sure that you are in user library if you are not sure check the link below.
    Access hidden user library files | Mac OS 10.7 and later
    Regards,
    Vinay

Maybe you are looking for

  • Emailing Form in PDF format instead on xml? -need help!-

    I have a webpage that has a link that directs customers to a pdf form I created with Adobe Designer 7.0 and when the customer is done filling out their information in the form and click's the submit email button. It comes to my inbox in an .xml! is t

  • Adobe AIR SDK (3.4.0.2710) Captive Runtime Not Updated

    Hi, I just downloaded the latest Adobe AIR SDK 3.4.0.2710. Looking at \runtimes\air-captive\win\Adobe AIR\Versions\1.0\Adobe AIR.dll it still says it is 3.4.2540. Will the captive runtime be updated to 3.4.2710? Thanks, John

  • Survey - Generate URL button is grayed out

    Hi, I have created survey in UI but when I click on Generate URL and enter Get file/send file, I get Generate URL button grayed out. Please suggest. I could able to generate URL for GUI but not in UI. Regards, Nikhil

  • Trouble with bridge mode and port forwarding

    I have a Westell Model 6100F DSL modem in bridge mode into my network and I'm having trouble forwarding ports. Is there any general guidance available to do this. I have set many of my friends networks up to allow port forwarding but all have been on

  • Filtering on used/unused photos within projects (un-/used e.g. in books, -)

    Hello, I'm trying to clean up my library by removing (archiving) all those unused photos. This means: all photos from a project should be removed which are not used in any album, book, web-gallery, etc. (or better: moved to a different backup project