background worker cancel problem

Discussion in 'Microsoft VB .NET' started by Smokey Grindel, Jan 7, 2008.

  1. I have a search function that runs in a background worker which can run
    long.. I want the user to be able to cancel that then run another search...
    but sometimes it throws an exception saying

    System.InvalidOperationException: This BackgroundWorker is currently busy
    and cannot run multiple tasks concurrently.

    What I did before the search button was pressed again was check if the
    worker is busy and if it is cancel the current search then start another...
    now how can i make sure the worker isnt workering before trying to start
    another? Even though I cancelled the work some work might still be
    processing before it realizes its cancelled and thats what seems to be
    causing the error... thanks!
     
    Smokey Grindel, Jan 7, 2008
    #1
    1. Advertisements

  2. Smokey Grindel

    Ryan Jones Guest

    You might be able to use a loop to look the current thread until you background worker is finished:

    While MyBackgroundWorker.IsBusy

    End While

    > On Monday, January 07, 2008 3:37 PM Smokey Grindel wrote:


    > I have a search function that runs in a background worker which can run
    > long.. I want the user to be able to cancel that then run another search...
    > but sometimes it throws an exception saying
    >
    > System.InvalidOperationException: This BackgroundWorker is currently busy
    > and cannot run multiple tasks concurrently.
    >
    > What I did before the search button was pressed again was check if the
    > worker is busy and if it is cancel the current search then start another...
    > now how can i make sure the worker isnt workering before trying to start
    > another? Even though I cancelled the work some work might still be
    > processing before it realizes its cancelled and thats what seems to be
    > causing the error... thanks!



    > Submitted via EggHeadCafe
    > ASP.NET Base64 Image Encoding via the Data: protocol
    > http://www.eggheadcafe.com/tutorial...e64-image-encoding-via-the-data-protocol.aspx
     
    Ryan Jones, Jan 16, 2011
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    985
    Guest
    Dec 1, 2005
  2. John Veldthuis

    Multiple Args to Background worker

    John Veldthuis, Dec 26, 2005, in forum: Microsoft VB .NET
    Replies:
    4
    Views:
    406
    John Veldthuis
    Dec 27, 2005
  3. Jesse Aufiero

    background worker in vb.net 2005

    Jesse Aufiero, Jul 6, 2007, in forum: Microsoft VB .NET
    Replies:
    4
    Views:
    454
    Phill W.
    Jul 9, 2007
  4. Jerry Spence1

    Getting a reference to the actual background worker

    Jerry Spence1, Feb 8, 2008, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    222
    Jerry Spence1
    Feb 11, 2008
  5. Jerry Spence1

    Background Worker Cross Thread UI problem

    Jerry Spence1, Mar 11, 2008, in forum: Microsoft VB .NET
    Replies:
    7
    Views:
    421
    Patrice
    Mar 12, 2008
Loading...

Share This Page