Microsoft® Visual Basic® 2010 Developer’s Handbook

Book description

Your expert guide to building modern applications with Visual Basic 2010

Take control of Visual Basic 2010—for everything from basic Windows and web development to advanced multithreaded applications. Written by Visual Basic experts, this handbook provides an in-depth reference on language concepts and features, as well as scenario-based guidance for putting Visual Basic to work. It's ideal whether you’re creating new applications with Visual Basic 2010 or upgrading projects built with an earlier version of the language.

Discover how to:

  • Use Visual Basic 2010 for Windows Forms and Windows Presentation Foundation projects

  • Build robust code using object-oriented programming techniques, such as classes and types

  • Work with events and delegates—and add your own events to custom classes

  • Program arrays, collections, and other data structures in the Microsoft .NET Framework

  • Solve problems quickly and easily using My namespace in Visual Basic

  • Dive into Microsoft LINQ, including LINQ to XML and LINQ to Entities

  • Tackle threading, multitasking, and multiprocessor development and debugging

  • Table of contents

    1. Microsoft® Visual Basic® 2010 Developer’s Handbook
    2. Dedication
    3. Foreword
    4. Introduction
      1. Who Should Read This Book
        1. Assumptions
      2. Who Should Not Read This Book
      3. Organization of This Book
      4. Conventions and Features in This Book
      5. System Requirements
      6. Code Samples
        1. Installing the Code Samples
        2. Using the Code Samples
      7. Acknowledgments
      8. Errata and Book Support
      9. We Want to Hear from You
      10. Stay in Touch
    5. I. Beginning with Language and Tools
      1. 1. Beginners All-Purpose Symbolic Instruction Code
        1. Starting Visual Studio for the First Time
        2. Console Applications
          1. Starting an Application
        3. Anatomy of a (Visual Basic) Program
        4. Starting Up with the Main Method
        5. Methods with and Without Return Values
          1. Defining Methods Without Return Values by Using Sub
          2. Defining Methods with Return Values by Using Function
        6. Declaring Variables
          1. Nullables
        7. Expressions and Definitions of Variables
          1. Defining and Declaring Variables at the Same Time
          2. Complex Expressions
          3. Boolean Expressions
        8. Comparing Objects and Data Types
          1. Deriving from Objects and Abstract Objects
        9. Properties
        10. Type Literal for Determining Constant Types
        11. Type Safety
          1. Local Type Inference
        12. Arrays and Collections
        13. Executing Program Code Conditionally
          1. If ... Then ... Else ... ElseIf ... End If
          2. The Logical Operators And, Or, Xor, and Not
          3. Comparison Operators That Return Boolean Results
          4. Short Circuit Evaluations with OrElse and AndAlso
          5. Select ... Case ... End Select
            1. The If Operator and IIf Function
        14. Loops
          1. For ... Next Loops
            1. Nesting For Loops
          2. For ... Each Loops
          3. Do ... Loop and While ... End While Loops
          4. Exit—Leaving Loops Prematurely
          5. Continue—Repeating Loops Prematurely
        15. Simplified Access to Object Properties and Methods Using With ... End With
        16. The Scope of Variables
        17. The += and –= Operators and Their Relatives
          1. The Bit Shift Operators << and >>
        18. Error Handling in Code
          1. Elegant Error Handling with Try/Catch/Finally
            1. Catching Multiple Exception Types
            2. Using the Finally Block
      2. 2. Introduction to the .NET Framework
        1. What Is .NET, and What Is It Composed Of?
        2. What Is an Assembly?
          1. What Is a Namespace?
            1. Embedding of Namespaces and Assemblies in Code Files and Projects: a Practical Example
          2. Common Language Runtime and Common Language Infrastructure
          3. The Framework Class Library and the Base Class Library
            1. The Common Type System
            2. Microsoft Intermediate Language and the Just-In-Time Compiler
      3. 3. Sightseeing
        1. Introduction
        2. Starting Visual Studio for the First Time: Selecting the Profile
        3. The Start Page: Where Your Developing Endeavors Begin
          1. Beginning Development Experience—Creating New Projects
            1. Managing Templates
            2. Modifying Templates
          2. Migrating from Previous Versions of Visual Studio to Visual Studio 2010
          3. Upgrading Projects created with Visual Studio 2003 Through 2008
        4. Upgrading Visual Basic 6.0 Applications to Visual Studio 2010
          1. Multitargeting of Visual Basic Applications by Using Visual Studio 2010
        5. The History of Multitargeting
          1. Multitargeting for New Projects
          2. Changing the Target Framework for Applications
            1. Understanding Profiles
            2. Client Profile is Default for Client Projects
        6. Interesting Read for Multitargeting
          1. Limitations of Multitargeting
            1. Lack of Round-Tripping Support
            2. Compromised Design Time Compatibility
            3. Non-Optimal Experience with Mixed Target Solutions
            4. Third-Party User Controls
        7. Zooming In the New and Improved WPF-Based IDE
          1. Managing Screen Real Estate
            1. Split Window
            2. Horizontal and Vertical Tab Group
            3. Multimonitor Support or Tear-Away Windows
          2. Persistence of Window Layout
          3. Common Use Scenarios
            1. Normal View
            2. Windows In Float
            3. Docking the Windows
        8. Searching, Understanding, and Navigating Code
          1. Navigate To
            1. Smart Searching Capabilities
            2. Navigating Between Code Blocks
            3. Highlighting and Navigating Between Symbol References
          2. Changing the Highlight Color
            1. Disabling Highlight References
        9. Regions and Outlining
        10. Architecture Explorer
          1. Sequence Diagram
          2. Class Diagram
          3. Coding Bottom Up
            1. Declare First Mode
            2. Consume First Mode
        11. The Generate From Usage Feature
          1. Customizing Types by Using the Generate New Type Dialog
        12. Extending Visual Studio
          1. Managing Visual Studio Extensions
          2. Extension Types
      4. 4. Introduction to Windows Forms—Designers and Code Editor by Example
        1. Case Example: the DVD Cover Generator
          1. Specifications for “Covers”
          2. Creating a New Project
        2. Designing Forms with the Windows Forms Designer
          1. Positioning Controls
            1. Guidelines and the Margin/Padding Properties of Controls
            2. Adjusting the Size and Position of Controls
            3. Selecting Multiple Controls and Specifying the Reference Control
          2. Performing Common Tasks on Controls by Using Smart Tags
          3. Dynamically Arranging Controls at Runtime
            1. Anchoring Controls with the Anchor Property
            2. Adjusting Controls Proportionately to Form Size Changes with TableLayoutPanel
            3. Creating Columns and Rows for the TableLayoutPanel
            4. Arranging Controls in the Cells of the TableLayoutPanel
            5. Anchoring Controls in the TableLayoutPanel
            6. Spanning Rows or Columns of the TableLayoutPanel
          4. Automatic Scrolling of Controls in Containers
          5. Selecting Controls That Users Can’t Reach with the Mouse
            1. Selecting Controls with the Properties Window
          6. Determining the Tab Order of Controls
          7. Using the Name, Text, and Caption Properties
            1. Specifying Accelerator Keys
          8. Setting up Accept and Cancel Buttons for a Form
          9. Adding Multiple Forms to a Project
          10. What’s Next?
          11. Naming Conventions for Controls in this Book
          12. Functions for Control Layout in the Designer
          13. Keyboard Shortcuts for Positioning Controls
        3. The Code Editor
          1. Setting the Editor Display to the Correct Size
          2. Many Roads Lead to the Code Editor
          3. IntelliSense—The Strongest Workhorse in the Coding Stable
            1. Filtering Elements in the Completion List
            2. Displaying Element Parameter Information
            3. Multiple Command Lines, Implicit Line Continuation, and Parameter Information
          4. Automatic Completion of Structure Keywords and Code Indentation
          5. Error Detection in the Code Editor
            1. Simple Error Detection in the Editor
            2. Editor Support for Runtime Errors
            3. Forcing Type Safety: Error Correction Options for Type Conflicts
          6. XML Documentation Comments for IntelliSense for Customized Objects and Classes
          7. Adding New Code Files to the Project
          8. Refactoring Code
            1. Refactoring Code (Adjusting Class Names) by Renaming Project Files or Object Properties
          9. Code Snippets Library
            1. Inserting Code Snippets with the Help of Connections
          10. Saving Application Settings with the Settings Designer
            1. Setting Up Settings Variables
            2. Using Settings Variables in Code
            3. Binding of Settings Values with Form and Control Properties
            4. Where Are Settings Stored?
          11. Congratulations!
      5. 5. Introduction to Windows Presentation Foundation
        1. What Is the Windows Presentation Foundation?
        2. What’s So New About WPF?
          1. 25 Years of Windows, 25 Years of Drawn Buttons
            1. Games and Protagonists
        3. How WPF Brings Designers and Developers Together
        4. Extensible Application Markup Language
          1. Event Handling in WPF and Visual Basic
        5. XAML Syntax Overview
        6. ImageResizer—a Practical WPF Example
          1. Defining Grid Columns and Rows for Arranging Controls
          2. Inserting a New Row Retroactively
          3. The Main Menu
          4. Binding Events to Controls
          5. Loading the Default Settings
          6. Organization Is Everything: Making the Output Path Freely Definable
          7. Making Final Preparations: Adding Pictures
          8. On to the Finish Line: Reducing Picture Size
          9. Adding a Project to an Existing Solution and Setting References
          10. The Heart of the Program: Image Resizing
          11. From Coach to Business Class
      6. 6. The Essential .NET Data Types
        1. Numeric Data Types
          1. Defining and Declaring Numeric Data Types
          2. Delegating Numeric Calculations to the Processor
          3. Numeric Data Types at a Glance
            1. Byte
            2. SByte
            3. Short
            4. UShort
            5. Integer
            6. UInteger
            7. Long
            8. ULong
            9. Single
            10. Double
            11. Decimal
          4. The Numeric Data Types at a Glance
            1. Avoiding Single and Double Rounding Errors
          5. Methods Common to all Numeric Types
            1. Converting Strings into Values and Avoiding Culture-Dependant Errors
            2. Performance and Rounding Issues
            3. Determining the Minimum and Maximum Values of a Numeric Type
          6. Special Functions for all Floating-Point Types
            1. Infinity
            2. Not a Number: NaN
            3. Converting with TryParse
          7. Special Functions for the Decimal Type
        2. The Char Data Type
        3. The String Data Type
          1. Strings—Yesterday and Today
          2. Declaring and Defining Strings
          3. Handling Empty and Blank Strings
          4. Automatic String Construction
          5. Assigning Special Characters to a String
          6. Memory Requirements for Strings
          7. No Strings Attached, or Are There? Strings are Immutable!
            1. Memory Optimization for Strings
            2. Determining String Length
            3. Retrieving Parts of a String
            4. Padding Strings
            5. Find and Replace Operations
            6. Trimming Strings
            7. Splitting Strings
          8. Iterating through Strings
          9. StringBuilder vs. String: When Performance Matters
          10. Performance Comparison: String vs. StringBuilder
        4. The Boolean Data Type
          1. Converting to and from Numeric Data Types
          2. Converting to and from Strings
        5. The Date Data Type
          1. TimeSpan: Manipulating Time and Date Differences
          2. A Library with Useful Functions for Date Manipulation
          3. Converting Strings to Date Values
            1. Conversions with Parse
            2. Conversion with ParseExact
        6. .NET Equivalents of Base Data Types
          1. The GUID Data Type
        7. Constants and Read-Only Fields (Read-Only Members)
          1. Constants
          2. Read-Only Fields
    6. II. Object-Oriented Programming
      1. 7. A Brief Introduction to Object-Oriented Programming
        1. Using Classes and Objects: When and Why?
          1. Mini Address Book—the Procedural Version
      2. 8. Class Begins
        1. What Is a Class?
        2. Instantiating Classes with New
          1. Initializing Public Fields During Instantiation
        3. New or Not New: About Objects and Reference Types
        4. Nothing
          1. Nothing as a Null Reference Pointer
          2. Nothing and Default Values
        5. Using Classes
        6. Value Types
          1. Creating a Value Type with a Structure
          2. Assigning a Value Type to a Variable
      3. 9. First Class Programming
        1. Using Properties
          1. Assigning Values to Properties
            1. Pre-Allocating Default Property Values for Autoimplemented Properties
          2. Passing Arguments to Properties
          3. Default Properties
          4. Avoid the Ultimate Property-No-Go
          5. Public Variables or Properties—a Question of Faith?
        2. Class Constructors: Defining What Happens in New
          1. Parameterized Constructors
        3. Class Methods with Sub and Function
        4. Overloading Methods, Constructors, and Properties
          1. Using Optional Parameters
          2. Mutual Calling of Overloaded Methods
          3. Mutual Calling of Overloaded Constructors
          4. Overloading Property Procedures with Parameters
        5. Specifying Variable Scope with Access Modifiers
          1. Access Modifiers and Classes
          2. Access Modifiers and Procedures (Subs, Functions, Properties)
          3. Access Modifiers and Variables
          4. Different Access Modifiers for Property Accessors
        6. Static Elements
          1. Static Methods
          2. Static Properties
        7. Distributing Class Code over Multiple Code Files by Using Partial
          1. Partial Class Code for Methods and Properties
      4. 10. Class Inheritance and Polymorphism
        1. Reusing Classes Through Inheritance
          1. Initializing Field Variables for Classes Without Default Constructors
        2. Overriding Methods and Properties
          1. Overriding Existing Methods and Properties of .NET Framework Classes
        3. Polymorphism
          1. A Simple Example of Polymorphism
          2. Using Polymorphism in Real World Applications
          3. Polymorphism and the Use of Me, MyClass, and MyBase
        4. Abstract Classes and Virtual Procedures
          1. Declaring a Class as Abstract with MustInherit
          2. Declaring a Method or Property of an Abstract Class as Virtual with MustOverride
        5. Interfaces
          1. Editor Support for Abstract Classes and Interfaces
            1. The Pitfalls of Automatic Code Completion with Interfaces or Abstract Classes
            2. Editor Support for Abstract Classes
          2. Interfaces that Implement Interfaces
          3. Binding Multiple Interfaces in a Class
        6. The Built-In Members of the Object Type
          1. Returning the String Representation of an Object with ToString
          2. Comparing Objects
          3. Equals, Is, and IsNot in Real World Scenarios
          4. The Methods and Properties of Object: An Overview
        7. Shadowing of Class Procedures
          1. Shadows as Interruptor of the Class Hierarchy
        8. Special Form “Module” in Visual Basic
        9. Singleton Classes and Self-Instantiating Classes
      5. 11. Developing Value Types
        1. A Practical Example of Structures
        2. Passing Value and Reference Parameters
        3. Constructors and Default Instantiations of Value Types
          1. No Default Constructor Code for Value Types
        4. When to Use Value Types—When to Use Reference Types
        5. Targeted Memory Assignment for Structure Members with the Attributes StructLayout and FieldOffset
      6. 12. Typecasting and Boxing Value Types
        1. Converting Primitive Types
        2. Converting to and from Strings
          1. Converting Strings by Using the Parse and ParseExact Method
          2. Converting Into Strings by Using the ToString Method
          3. Catching Type Conversion Failures
        3. Casting Reference Types by Using DirectCast
          1. TryCast—Determining Whether Casting Is Possible
          2. IsAssignableFrom—Casting on the Fly
        4. Boxing Value Types
          1. What DirectCast Cannot Do
          2. To Box or Not to Box
        5. Changing the Values of Interface-Boxed Value Types
      7. 13. Dispose, Finalize, and the Garbage Collector
        1. The Garbage Collector in .NET
          1. How the Garbage Collector Works
        2. The Speed in Allocating Memory for New Objects
        3. Finalize
          1. When Finalize Does Not Take Place
        4. Dispose
          1. Implementing a High Resolution Timer as IDisposable
          2. Visual Basic Editor Support for Inserting a Disposable Pattern
        5. Targeted Object Release with Using
      8. 14. Operators for Custom Types
        1. Introduction to Operator Procedures
        2. Preparing a Structure or Class for Operator Procedures
        3. Implementing Operators
          1. Overloading Operator Procedures
        4. Implementing Comparison Operators
        5. Implementing Type Conversion Operators for Use with CType
        6. Implementing True and False Evaluation Operators
        7. Problem Handling for Operator Procedures
          1. Beware When Using Reference Types!
        8. Implementable Operators: an Overview
      9. 15. Events, Delegates, and Lambda Expressions
        1. Consuming Events with WithEvents and Handles
        2. Raising Events
          1. Events Cannot Be Inherited—the Detour Via Onxxx
        3. Providing Event Parameters
          1. The Event Source: sender
          2. Detailed Event Information: EventArgs
        4. Delegates
          1. Passing Delegates to Methods
        5. Lambda Expressions
          1. Single-Line Expression Lambdas and Multi-Line Statement Lambdas
        6. Embedding Events Dynamically with AddHandler
        7. Implementing Your Own Event Handlers
      10. 16. Enumerations
        1. Introduction to Enumerations
        2. Determining the Values of Enumeration Elements
          1. Duplicate Values Are Allowed!
        3. Determining the Types of Enumeration Elements
          1. Retrieving the Types of Enumeration Elements at Runtime
        4. Converting Enumerations to Other Types
          1. Converting to Numeric Values and Vice Versa
          2. Parsing Strings into Enumerations
        5. Flags Enumerations
          1. Querying Flags Enumerations
      11. 17. Developing with Generics
        1. Introduction
          1. Generics: Using One Code Base for Different Types
        2. Solution Approaches
        3. Standardizing the Code Base of a Type by Using Generics
        4. Constraints
          1. Constraining Generic Types to a Specific Base Class
          2. Constraining a Generic Type to Specific Interfaces
          3. Constraining a Generic Type to Classes with a Default Constructor
          4. Constraining a Generic Class to Value Types
          5. Combining Constraints and Specifying Multiple Type Parameters
      12. 18. Advanced Types
        1. Nullable Value Types
          1. Be Careful When Using Boolean Expressions Based on Nullables
          2. Special Characteristics of Nullable During Boxing
          3. The Difference Between Nothing and Nothing as a Default Value
        2. Generic Delegates
          1. Action(Of T)
          2. Function(Of T)
        3. Tuple(Of T)
        4. Type Variance
        5. Extension Methods
          1. The Main Application Area of Extension Methods
          2. Using Extension Methods to Simplify Collection Initializers
    7. III. Programming with .NET Framework Data Structures
      1. 19. Arrays and Collections
        1. Array Basics
        2. Initializing Arrays
          1. Changing Array Dimensions at Runtime
          2. The Magic of ReDim
          3. Pre-Allocating Values of Array Elements in Code
          4. Type Inference When Using Array Initializers
            1. Dominant Types
          5. Multidimensional Arrays and Jagged Arrays
          6. Jagged Arrays
          7. Important Array Properties and Methods
            1. Determining the Number of Array Elements by Using Length
            2. Sorting Arrays with Array.Sort
            3. Reversing the Array Order with Array.Reverse
            4. Searching a Sorted Array with Array.BinarySearch
          8. Implementing Sort and BinarySearch Custom Classes
            1. Implementing Class Comparability with IComparable
          9. Using Lambdas with Array Methods
        3. Enumerators
          1. Custom Enumerators with IEnumerable
        4. Collection Basics
        5. Initializing Collections
          1. Using Extension Methods to Simplify Collection Initializers
        6. Important Collections of .NET Framework
          1. ArrayList: Universal Storage for Objects
          2. Type-Safe Collections Based on CollectionBase
          3. Hashtables: Fast Lookup for Objects
          4. Using Hashtables
            1. Processing Speed of Hashtables
            2. Why the Access Time to Hashtable Elements Is Almost Constant...
            3. ... And Why You Should Know About It
          5. Using Custom Classes as Key
            1. Keys Must Be Immutable
          6. Enumerating Data Elements in a Hashtable
          7. The DictionaryBase Class
          8. Queue: the FIFO Principle
          9. Stack: the LIFO Principle
          10. SortedList: Keeping Elements Permanently Sorted
        7. Generic Collections
          1. List(Of ) Collections and Lambda Expressions
            1. ForEach and the Generic Action Delegate
            2. Sort and the Generic Comparison Delegate
            3. Find and the Generic Predicate Delegate
          2. KeyedCollection: Key/Dictionary Collections with Additional Index Queries
          3. Linking Elements with LinkedList(Of )
      2. 20. Serialization
        1. Introduction to Serialization Techniques
          1. Serializing with SoapFormatter and BinaryFormatter
            1. Universal SOAP File Serializer and Deserializer
            2. Universal Binary File Serializer and Deserializer
            3. File Serializer Functionality
        2. Shallow and Deep Object Cloning
          1. The Universal DeepClone Method
        3. Serializing Objects with Circular References
          1. Serializing Objects of Different Versions When Using BinaryFormatter and SoapFormatter Classes
        4. XML Serialization
          1. Checking the Version Independence of the XML File
          2. Serialization Problems with KeyedCollection
      3. 21. Attributes and Reflection
        1. Introduction to Attributes
          1. Using Attributes with ObsoleteAttribute
          2. Visual Basic-Specific Attributes
        2. Introduction to Reflection
          1. The Type Class as the Origin for All Type Examinations
          2. Class Analysis Functions Provided by a Type Object
          3. Object Hierarchy of MemberInfo and Casting to a Specific Info Type
          4. Determining Property Values with PropertyInfo at Runtime
        3. Creating Custom Attributes and Recognizing Them at Runtime
          1. Determining Custom Attributes at Runtime
    8. IV. Development Simplifications in Visual Basic 2010
      1. 22. Using My as a Shortcut to Common Framework Functions
        1. Visual Basic 2010 Simplifications Using the Example of the DotNetCopy Backup Tool
          1. DotNetCopy Options: /Autostart and /Silent
        2. The Principle Functionality of DotNetCopy
        3. The My Namespace
        4. Calling Forms Without Instantiation
        5. Reading Command-Line Arguments with My.Application.CommandLineArgs
        6. Targeted Access to Resources with My.Resources
          1. Creating and Managing Resource Elements
          2. Retrieving Resources with My.Resources
        7. Writing Localizable Applications with Resource Files and the My Namespace
        8. Simplified File Operations with My.Computer.FileSystem
        9. Using Application Settings with My.Settings
          1. Saving Application Settings with User Scope
      2. 23. The Application Framework
        1. Application Framework Options
          1. A Windows XP Look and Feel for Your Applications—Enabling Visual XP Styles
          2. Preventing Multiple Application Starts—Creating a Single Instance Application
          3. Save My.Settings Automatically on Shutdown
          4. Specifying the User Authentication Mode
          5. Specifying the End of Your Application—the Shutdown Mode
          6. Displaying a Splash Dialog when Starting Complex Applications—Start Screen
        2. Adding a Code File to Handle Application Events (Start, End, Network Status, Global Exceptions)
    9. V. Language-Integrated Query—LINQ
      1. 24. Introduction to LINQ (Language-Integrated Query)
        1. Getting Started with LINQ
          1. LINQ: Based on Extension Methods
        2. The Where Method
        3. The Select Method
          1. Anonymous Types
          2. Type Inference for Generic Type Parameters
        4. Combining LINQ Extension Methods
        5. Simplified Use of LINQ Extension Methods with the LINQ Query Syntax
      2. 25. LINQ to Objects
        1. Getting Started with LINQ to Objects
        2. Anatomy of a LINQ Query
        3. LINQ Query Performance
        4. Concatenating LINQ Queries and Delayed Execution
          1. Cascading Queries
          2. Parallelizing LINQ Queries with AsParallel
          3. Guidelines for Creating LINQ Queries
          4. Forcing Query Execution with ToArray or ToList
        5. Combining Multiple Collections
          1. Combining Collections Implicitly
          2. Combining Collections Explicitly
        6. Grouping Collections
          1. Grouping Collections from Multiple Collections
          2. Group Join
        7. Aggregate Functions
          1. Returning Multiple Different Aggregations
          2. Combining Grouped Queries and Aggregations
      3. 26. LINQ to XML
        1. Getting Started with LINQ to XML
        2. Processing XML Documents—Yesterday and Today
        3. XML Literals: Using XML Directly in Code
          1. Including Expressions in XML Literals
        4. Creating XML Documents with LINQ
        5. Querying XML Documents with LINQ to XML
        6. IntelliSense Support for LINQ To XML Queries
          1. Using Prefixes (fleet and article)
      4. 27. LINQ to Entities: Programming with Entity Framework
        1. Prerequisites for Testing the Examples
          1. Downloading and Installing SQL Server 2008 R2 Express Edition with Advanced Services
          2. Installing the AdventureWorks Sample Databases
          3. The Working Principle of an Entity Data Model
        2. LINQ to Entities: the First Practical Example
          1. Changing the Name of the Entity Set
          2. Changing the Entity Container Name Retroactively
          3. Editing the .edmx-File as XML Outside the Designer
        3. Querying an Entity Model
          1. Querying Data with LINQ to Entities Queries
          2. How Queries Get to the Data Provider—Entity SQL (eSQL)
          3. A Closer Look at Generated SQL Statements
          4. Lazy Loading and Eager Loading in Entity Framework
            1. Loading Data Manually and Retroactively During Lazy Loading
            2. Using Eager Loading for Certain Relationships
          5. Avoiding Anonymous Result Collections in Join Queries via Select
          6. Compiled Queries
        4. Modifying, Saving, and Deleting Data
          1. Saving Data Modifications to the Database by Using SaveChanges
          2. Inserting Related Data into Data Tables
          3. Deleting Data from Tables
          4. Concurrency Checks
        5. Updating a Data Model from a Database
        6. Model-First Design
        7. Inheritance in the Conceptual Data Model
        8. Executing T-SQL Commands Directly in the Object Context
        9. Working with Stored Procedures
        10. Looking Ahead
    10. VI. Parallelizing Applications
      1. 28. Programming with the Task Parallel Library (TPL)
        1. Introduction to Threading
        2. Various Options for Starting a Thread
          1. Using the Thread Class
            1. Background Threads Always End When the Main Application Ends
            2. Simplifying Thread Start With Multi-Line Lambdas
          2. Calling Delegates Asynchronously
          3. Using the Task Class
          4. Using a Thread Pool’s Thread directly
        3. How to Access Windows Controls from Non-UI Threads
        4. Parallelization with Parallel.For and Parallel.ForEach
          1. Parallel.For
            1. Example: Parallelizing the ImageResizer
          2. Parallel.ForEach
          3. Using ParallelLoopStates—Exit For for Parallel.For and Parallel.ForEach
          4. Avoiding Errors When Parallelizing Loops
        5. Working with Tasks
          1. Waiting on Task Completion—WaitOne, WaitAny, and WaitAll
          2. Tasks with and Without Return Values
          3. How To Avoid Freezing the User Interface While Waiting For Tasks To Finish
          4. Cancelling Tasks by Using CancellationToken
        6. Synchronizing Threads
          1. Synchronizing Threads with SyncLock
          2. The Monitor Class
            1. Monitor—Wait—Pulse
          3. Synchronizing Limited Resources with Mutex
        7. What’s Next?
    11. A.
      1. Klaus Löffelmann
      2. Sarika Calla Purohit
    12. Index
    13. About the Authors
    14. Copyright

    Product information

    • Title: Microsoft® Visual Basic® 2010 Developer’s Handbook
    • Author(s): Klaus Löffelmann and Sarika Calla Purohit
    • Release date: August 2011
    • Publisher(s): Microsoft Press
    • ISBN: 9780735663138