Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# 2.0 BackgroundWorker

C# 2.0 BackgroundWorker

Scheduled Pinned Locked Moved C#
csharpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kselman
    wrote on last edited by
    #1

    I got an app where I use the backgroundworker and when it's done it fires off the BackgroundWorkerCompleted event. Which is all good. but I need to reused the object later on. I get an exception that the BackgroundWorker has already completed. So I tried myBackgroundWorker = new BackgroundWorker(); but none of the events are hooked up any more and it just sits there. Is there anyway to reset it?:confused: or do I have to set all the properties each time I use it? -Kevin

    N B 2 Replies Last reply
    0
    • K kselman

      I got an app where I use the backgroundworker and when it's done it fires off the BackgroundWorkerCompleted event. Which is all good. but I need to reused the object later on. I get an exception that the BackgroundWorker has already completed. So I tried myBackgroundWorker = new BackgroundWorker(); but none of the events are hooked up any more and it just sits there. Is there anyway to reset it?:confused: or do I have to set all the properties each time I use it? -Kevin

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      kselman wrote:

      myBackgroundWorker = new BackgroundWorker();

      You must reconnect the events, this is a new instance of BackgroundWorker. You can't rest the original because the thread has already completed its work and has been returned to the pool.


      only two letters away from being an asset

      1 Reply Last reply
      0
      • K kselman

        I got an app where I use the backgroundworker and when it's done it fires off the BackgroundWorkerCompleted event. Which is all good. but I need to reused the object later on. I get an exception that the BackgroundWorker has already completed. So I tried myBackgroundWorker = new BackgroundWorker(); but none of the events are hooked up any more and it just sits there. Is there anyway to reset it?:confused: or do I have to set all the properties each time I use it? -Kevin

        B Offline
        B Offline
        Bob Nadler
        wrote on last edited by
        #3

        If you're re-starting the worker with RunWorkerAsync() the only exception would be InvalidOperationException, which means the worker is still running (IsBusy is true). What exception are you getting? --Bob

        K 1 Reply Last reply
        0
        • B Bob Nadler

          If you're re-starting the worker with RunWorkerAsync() the only exception would be InvalidOperationException, which means the worker is still running (IsBusy is true). What exception are you getting? --Bob

          K Offline
          K Offline
          kselman
          wrote on last edited by
          #4

          Welp.. Its working now.. not sure what was going on with it before. Unfortunately I changed too many things between testing and Im no longer receiving the Exception. It said something about "Background Worker has already completed" I think was I calling ReportProgress during the Completed event.. but I tried to recreate the problem to report to you here.. but that didnt cause the exception. I also had a pointer to a helper class that was init'd outside of the DoWork function, but I put that back in and it still works.. *shrug* sorry.. i usually dont jump the gun and post a request for help.. but It sure seemed that I could not re-use the B.W. with out hooking its events back up. Which is not the case.. Just calling RunWorkerAsync() re-runs it as expected. You reply did help, because you seemed confident to be able to re-use RunWorkerAsync and sure enough the problem was on my end.. Thanks for the quick replies.. -- Kevin

          B 1 Reply Last reply
          0
          • K kselman

            Welp.. Its working now.. not sure what was going on with it before. Unfortunately I changed too many things between testing and Im no longer receiving the Exception. It said something about "Background Worker has already completed" I think was I calling ReportProgress during the Completed event.. but I tried to recreate the problem to report to you here.. but that didnt cause the exception. I also had a pointer to a helper class that was init'd outside of the DoWork function, but I put that back in and it still works.. *shrug* sorry.. i usually dont jump the gun and post a request for help.. but It sure seemed that I could not re-use the B.W. with out hooking its events back up. Which is not the case.. Just calling RunWorkerAsync() re-runs it as expected. You reply did help, because you seemed confident to be able to re-use RunWorkerAsync and sure enough the problem was on my end.. Thanks for the quick replies.. -- Kevin

            B Offline
            B Offline
            Bob Nadler
            wrote on last edited by
            #5

            Good to hear it's working. :) I have an instance of a class which is a subclass of BackgroundWorker that reuses DoWork many many times. Never had a problem with it. - Bob

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups