Results 1 to 4 of 4

Thread: BackgroundWorker1 or System.Threading.Thread

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    184

    BackgroundWorker1 or System.Threading.Thread

    What is the difference in using:

    BackgroundWorker1 or System.Threading.Thread

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: BackgroundWorker1 or System.Threading.Thread

    The BackgroundWorker is a component that wraps a thread. It has the advantage that it provides a couple of events that, when raised, are raised on the UI thread rather than in the background thread. Other than that, there really isn't much difference at all, as one is a wrapper built on the other.
    My usual boring signature: Nothing

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: BackgroundWorker1 or System.Threading.Thread

    Here is a thread where a guy asks something similar. There are more details about threading in general there.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: BackgroundWorker1 or System.Threading.Thread

    Parallelism is about having multiple tasks performed simultaneously. Parallelism is achieved using multi-threading and multi-threading in .NET is achieved using the Thread class. Each Thread represents an area within which statements can be executed in serial so multiple Threads allows multiple instructions to be executed in parallel.

    The BackgroundWorker is several layers of abstraction higher than the Thread class. The BackgroundWorker makes use of the ThreadPool class and that makes use of the Thread class. The BackgroundWorker was designed specifically for use in scenarios where you have a Windows GUI application within which you want to perform some long-running task and update the UI during and/or after that task. If you were to perform that task on the UI thread then your GUI would freeze. You could achieve the same thing with the Thread class explicitly but updating the UI is fiddly in that case. The BackgroundWorker enables you to perform a task in the background and update the UI by simply calling methods and handling events, which we've all done before. The one rule to remember is that you can never access a control within the DoWork event handler.

    For a BackgroundWorker example, follow the CodeBank link in my signature and check out my thread on Using The BackgroundWorker. To learn how to update the UI from a background thread without using a BackgroundWorker, check out my CodeBank thread on Accessing Controls From Worker Threads.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width