• (2 Pages)
  • +
  • 1
  • 2

The Background Worker How to use a background worker. Rate Topic: ***** 2 Votes

#16 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2290
  • View blog
  • Posts: 9,528
  • Joined: 29-May 08

Posted 31 May 2013 - 12:24 AM

macosxnerd101: Let me have swing at it or them first.




Quote

Why does this article contain countless sentence fragments that make no sense?
Is the English?


Big_Android_Doris:
U sum sorta gramma nazi?
or
Are you prejudiced against Dyslexic content creators?

Further more which version are you comparing to? The Queen's English, American English, Estuary English, Ye Olde World English, Shakespearean or an accented English? like Yorkshire. which even has sub dialects for example the Barnsley (from where I originate) accent. I think in Barnsley and have to first translate the to whatever this "standard" English.

Combine that with other problems I suffer from like Dyslexia, Audio Processing Disorder (difficulty differentiating the phonemes of language) and Irlen syndrome. It can be physical and mentally exhausting, as well as frustrating. Since there a big disjuncture in my mental and intelligence capabilities and what I physical produce. Compared with to other I can seem like I'm lazy because it take me a disproportionate amount of time to produce comparable content.

Spell check can only check the spelling of the words. Correct contextual usage is harder to see, especially for me. The tutorial was created in 2009 and has had a minimum of 105K of views. I think it is actually a lot more since the we (DIC) has a forum upgrade that reset them, and the tutorial existed before that. If you were to take the time to investigate (which I suspect you wouldn't) and review the progression of the tutorials. I believe you find that they improve, since only generating and writing content will improve your quality of them.

Do you speak from a voice of authority? By which I mean a content producer.
What content have you produced?
Can we see it?
Are you willing to place yourself and the content you produce on to the sacrificial alter of the internet.
To be under the knife of a high priest of the church of the flying spaghetti monster for your linguistic fails.



Quote

Why is the huge, complex mess of code needed?

A lot of the complexity arises from the threading model used in Windows and the cross thread communications and the marshaling of data across them. The thread on which GUI control is created on, is the owner of it. Since the background worker uses internally a separate thread to enable simultaneous operation with the GUI thread, delegates are need to access controls on the form(s).

You can always create a new thread yourself. Or if you are use a new version of .net (.net 4.0 or later) the use tasks, but this still involve cross thread communications and the use of delegates.

Quote

If MS wanted us to use this extremely common feature: Run This Code In The Background

Common feature where?

Quote

Why can't the entire mess just be one line of code:
Call RunInTheBackground(mySubName)



Done.


First point, use the code tags for code or use the il tag for small single line code example.
Or didn't you read the background text of, or that big yellow box above the reply box?

Are you a vb6 coder? Call {method name} isn't required in vb.net.


Quote

Sheezess. I can't invest all this time, coding, and debugging...

Why are you even bothering then?
Debugging Skills are essential to learn, your code isn't going to be perfect.

Quote

... just to do something that should ALREADY
be a built-in call.

Your complaining to me, because your frustrated that you can't understand or use it.

It is already a built in call, you just don't know how to use it because you haven't invested the time to read the publicly available documentation (MSDN), or even do a little experimentation.

There are multiple ways to do it. All of which boil down to Threads and Tasks
Do you want synchronous or asynchronous results?

Which way is best for your situation is done to you to decide, which one meets you requirements.
You are the one doing the engineering for your project.

Microsoft ain't psychics who can predict the intent of you code.

vb.net is a descended from vb6 which is single threaded, if you wanted it you write the multi-thread usage yourself. It was even more complex.

Also multi-threaded code incurs a cost (it could even be slower), and is inherently non-deterministic.
So is hard to get get use to, thus hard do correctly.

X = X + 1 or X += 1 isn't thread safe.

You need to use Interlocked.Increment(X).

Multiple access to shared resource need coordination and control, is that via Locks or mutexes or some other synchronization mechanism?

For a large majority of the use cases it isn't even needed.

This post has been edited by AdamSpeight2008: 31 May 2013 - 12:40 AM

Was This Post Helpful? 1
  • +
  • -

#17 ianbhenderson73  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-May 15

Posted 11 May 2015 - 03:42 PM

This is a great tutorial, and I can already see it being very useful.

I could really use your help on extending this a bit: I have a VB.net winform which contains a combo box and a button - the code behind the button calls a method within a module which itself calls other methods within that same module.

Essentially what I've built is an application which takes an incoming spreadsheet file, imports the data into a database and performs a number of operations on that date. So the method which is initially being called in the module is then running a series of sequential sub-processes. I've coded the whole thing so that it updates a text box on the UI which lets the user know exactly what's going on. The difficulty that I face is that I've built a function which updates the UI textbox. So in essence, I have three levels of code - the code directly behind the form, the code being called by the form code (in a separate module file) and the code being called by the module code in a separate function file.

The main reason for giving so much feedback is that sometimes these incoming spreadsheets can be quite large and it means that the user isn't sitting staring at a blank application that doesn't appear to be doing anything. I'm also expecting to have to build functionality for handling more than one type of file, so the function approach saves me having to write the same code over and over. My difficulty is this: I can wrap up the code behind the form button in a Background Worker and it works a treat. It does not however update the status window and therefore the user is effectively running blind. It would be good to know if it's possible to wrap a Background Worker in a Background Worker, but I just can't get my head around what I need to do.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2