I am dealing with some MSDN good examples, plus some books on ADO.Internet. What every one has in keeping is applying the purposeOrclick onOrpull-drop design time feature in Visual Studio to build up database programs, binding data sets to controls etc.

And also the resulting code does all DB access within the GUI thread, so far as I will tell. This seems like bad practice, and annoying behavior of the use of the database access once queries begins to consider time.

Shall We Be Held missing something ? Is how we are designed to develop database programs ? It's my job to woudn't think hard about placing network IO inside a seperate thread, always.

Yes, it's an awful idea unless of course you actually don't worry about getting the GUI hang. In some instances, particularly for "fast and dirty" tools, that's really the best choice. Whether it means you will get something to some user who's just going for doing things for a few days anyway and likes you obtaining the task finished soon instead of always getting a responsive UI, plus there is little point putting things off hopping between threads.

But no, it isn't how you are designed to develop database programs which should stay responsive.

However, I'm able to realise why books and lessons get it done - a minimum of to some degree. If they are attempting to train you database access instead of threads, this means that the greater proportion from the code will probably be highly relevant to the topic matter than if everything was absolutely "production code". I understand from experience it's difficult to keep "teaching code" as clean as you would really like.

However, It would be advisable for such lessons and books to describe this right in advance, so that they don't result in improper habits.

Observe that the primary trouble with this practice is not related to threads, however with separation of concerns. By binding database access so tightly towards the UI, they lose the options available by separation, and can require DB changes once the UI changes and the other way around.

Whether or not this matters to stay in exactly the same thread or otherwise will rely on the conditions, platform, etc.

Lots of MSDN good examples and Visual Studio itself let the "wise form" antipattern in which you drag stuff around the canvas and wire up some small code and you've got a functional something. They're striving at easy entry-level without lots of complications with this particular stuff.

It might be more optimal is to possess a worker thread to complete anything IO intensive and your GUI responsive (unless of course the aim is to buy something employed in ten minutes).

Oftentimes, you'd certainly wish to implement separation between your GUI and also the data access code.

However, most books are supplying info on features, this is not on architecture guidelines.

Whether this really is bad or otherwise entirely is dependent on the kind of application. When the queries are of the character that they don't take considerable time, it might not be an awful idea to help keep threads complexity from the picture. But the moment you begin to possess time intensive queries you'll most likely wish to have them by themselves worker thread.

Yes its bad.

Let's say your query takes 20 seconds? Goodbye UI.

IMHO, the main reason a lot of samples are made such as this is the fact that async designs insInternet are very untidy.

Let's suppose your samples appeared as if this:

    private void BasicAsyncWithNoProgress() {

        if (Application.Current.Dispatcher.Thread != System.Threading.Thread.CurrentThread) {
            Application.Current.Dispatcher.Invoke((System.Windows.Forms.MethodInvoker) BasicAsyncWithNoProgress, null);
            return;
        }

        // Do Work 
    }

Contrast this for an invented syntax (that may be accomplished with postsharp)

[NotOnUIThread]
private void BasicAsyncWithNoProgress() {
        // Do Work 
}