Home Page Icon
Home Page
Table of Contents for
About the Authors
Close
About the Authors
by Adam Freeman, Allen Jones
Visual C# 2010 Recipes: A Problem-Solution Approach
Copyright
About the Authors
About the Technical Reviewer
Acknowledgments
Introduction
1. Application Development
1.1. Create a Console Application from the Command Line
1.1.1. Problem
1.1.2. Solution
1.1.3. How It Works
1.1.3.1. The Code
1.1.3.2. Usage
1.2. Create a Windows-Based Application from the Command Line
1.2.1. Problem
1.2.2. Solution
1.2.3. How It Works
1.2.3.1. The Code
1.2.3.2. Usage
1.3. Create and Use a Code Module
1.3.1. Problem
1.3.2. Solution
1.3.3. How It Works
1.3.3.1. Usage
1.4. Create and Use a Code Library from the Command Line
1.4.1. Problem
1.4.2. Solution
1.4.3. How It Works
1.4.3.1. Usage
1.5. Access Command-Line Arguments
1.5.1. Problem
1.5.2. Solution
1.5.3. How It Works
1.5.3.1. The Code
1.5.3.2. Usage
1.6. Include Code Selectively at Build Time
1.6.1. Problem
1.6.2. Solution
1.6.3. How It Works
1.6.3.1. The Code
1.6.3.2. Usage
1.6.4. Notes
1.7. Access a Program Element That Has the Same Name As a Keyword
1.7.1. Problem
1.7.2. Solution
1.7.3. How It Works
1.7.3.1. The Code
1.8. Create and Manage Strongly Named Key Pairs
1.8.1. Problem
1.8.2. Solution
1.8.3. How It Works
1.9. Give an Assembly a Strong Name
1.9.1. Problem
1.9.2. Solution
1.9.3. How It Works
1.9.3.1. The Code
1.9.3.2. Usage
1.10. Verify That a Strongly Named Assembly Has Not Been Modified
1.10.1. Problem
1.10.2. Solution
1.10.3. How It Works
1.11. Delay-Sign an Assembly
1.11.1. Problem
1.11.2. Solution
1.11.3. How It Works
1.12. Sign an Assembly with an Authenticode Digital Signature
1.12.1. Problem
1.12.2. Solution
1.12.3. How It Works
1.12.3.1. Usage
1.13. Create and Trust a Test Software Publisher Certificate
1.13.1. Problem
1.13.2. Solution
1.13.3. How It Works
1.14. Manage the Global Assembly Cache
1.14.1. Problem
1.14.2. Solution
1.14.3. How It Works
1.15. Prevent People from Decompiling Your Code
1.15.1. Problem
1.15.2. Solution
1.15.3. How It Works
1.16. Manipulate the Appearance of the Console
1.16.1. Problem
1.16.2. Solution
1.16.3. How It Works
1.16.3.1. The Code
1.17. Create a Static Class
1.17.1. Problem
1.17.2. Solution
1.17.3. How It Works
1.17.3.1. The Code
1.18. Create an Anonymous Type
1.18.1. Problem
1.18.2. Solution
1.18.3. How It Works
1.18.3.1. The Code
1.19. Create an ExpandoObject Dynamic Type
1.19.1. Problem
1.19.2. Solution
1.19.3. How It Works
1.19.3.1. The Code
1.20. Define an Automatically Implemented Property
1.20.1. Problem
1.20.2. Solution
1.20.3. How It Works
1.20.3.1. The Code
1.21. Overload an Operator
1.21.1. Problem
1.21.2. Solution
1.21.3. How It Works
1.21.3.1. The Code
1.22. Define a Conversion Operator
1.22.1. Problem
1.22.2. Solution
1.22.3. How It Works
1.22.3.1. The Code
1.23. Handle an Event with an Anonymous Function
1.23.1. Problem
1.23.2. Solution
1.23.3. How It Works
1.23.3.1. The Code
1.24. Implement a Custom Indexer
1.24.1. Problem
1.24.2. Solution
1.24.3. How It Works
1.24.3.1. The Code
2. Data Manipulation
2.1. Manipulate the Contents of a String Efficiently
2.1.1. Problem
2.1.2. Solution
2.1.3. How It Works
2.1.3.1. The Code
2.2. Encode a String Using Alternate Character Encoding
2.2.1. Problem
2.2.2. Solution
2.2.3. How It Works
2.2.3.1. The Code
2.2.3.2. Usage
2.2.4. Notes
2.3. Convert Basic Value Types to Byte Arrays
2.3.1. Problem
2.3.2. Solution
2.3.3. How It Works
2.3.3.1. The Code
2.4. Base64 Encode Binary Data
2.4.1. Problem
2.4.2. Solution
2.4.3. How It Works
2.4.3.1. The Code
2.5. Validate Input Using Regular Expressions
2.5.1. Problem
2.5.2. Solution
2.5.3. How It Works
2.5.3.1. The Code
2.5.3.2. Usage
2.5.4. Notes
2.6. Use Compiled Regular Expressions
2.6.1. Problem
2.6.2. Solution
2.6.3. How It Works
2.6.3.1. The Code
2.7. Create Dates and Times from Strings
2.7.1. Problem
2.7.2. Solution
2.7.3. How It Works
2.7.3.1. The Code
2.8. Add, Subtract, and Compare Dates and Times
2.8.1. Problem
2.8.2. Solution
2.8.3. How It Works
2.8.3.1. The Code
2.9. Sort an Array or a Collection
2.9.1. Problem
2.9.2. Solution
2.9.3. How It Works
2.9.3.1. The Code
2.10. Copy a Collection to an Array
2.10.1. Problem
2.10.2. Solution
2.10.3. How It Works
2.10.3.1. The Code
2.11. Use a Strongly Typed Collection
2.11.1. Problem
2.11.2. Solution
2.11.3. How It Works
2.11.3.1. The Code
2.12. Create a Generic Type
2.12.1. Problem
2.12.2. Solution
2.12.3. How It Works
2.12.3.1. The Code
2.13. Store a Serializable Object to a File
2.13.1. Problem
2.13.2. Solution
2.13.3. How It Works
2.13.3.1. The Code
2.14. Serialize an Object Using JSON
2.14.1. Problem
2.14.2. Solution
2.14.3. How It Works
2.14.3.1. The Code
2.15. Read User Input from the Console
2.15.1. Problem
2.15.2. Solution
2.15.3. How It Works
2.15.3.1. The Code
2.16. Using Large Integer Values
2.16.1. Problem
2.16.2. Solution
2.16.3. How It Works
2.16.3.1. The Code
2.17. Select Collection or Array Elements
2.17.1. Problem
2.17.2. Solution
2.17.3. How It Works
2.17.3.1. The Code
2.18. Remove Duplicate Items from an Array or Collection
2.18.1. Problem
2.18.2. Solution
2.18.3. How It Works
2.18.3.1. The Code
3. Application Domains, Reflection, and Metadata
3.1. Create an Application Domain
3.1.1. Problem
3.1.2. Solution
3.1.3. How It Works
3.1.3.1. The Code
3.2. Create Types That Can Be Passed Across Application Domain Boundaries
3.2.1. Problem
3.2.2. Solution
3.2.3. How It Works
3.2.3.1. The Code
3.3. Avoid Loading Unnecessary Assemblies into Application Domains
3.3.1. Problem
3.3.2. Solution
3.3.3. How It Works
3.3.3.1. The Code
3.4. Create a Type That Cannot Cross Application Domain Boundaries
3.4.1. Problem
3.4.2. Solution
3.4.3. How It Works
3.5. Load an Assembly into the Current Application Domain
3.5.1. Problem
3.5.2. Solution
3.5.3. How It Works
3.5.3.1. The Code
3.6. Execute an Assembly in a Different Application Domain
3.6.1. Problem
3.6.2. Solution
3.6.3. How It Works
3.6.3.1. The Code
3.6.3.2. Usage
3.7. Instantiate a Type in a Different Application Domain
3.7.1. Problem
3.7.2. Solution
3.7.3. How It Works
3.7.3.1. The Code
3.8. Pass Data Between Application Domains
3.8.1. Problem
3.8.2. Solution
3.8.3. How It Works
3.8.3.1. The Code
3.9. Unload Assemblies and Application Domains
3.9.1. Problem
3.9.2. Solution
3.9.3. How It Works
3.9.3.1. The Code
3.10. Retrieve Type Information
3.10.1. Problem
3.10.2. Solution
3.10.3. How It Works
3.10.3.1. The Code
3.11. Test an Object's Type
3.11.1. Problem
3.11.2. Solution
3.11.3. How It Works
3.11.3.1. The Code
3.12. Instantiate an Object Using Reflection
3.12.1. Problem
3.12.2. Solution
3.12.3. How It Works
3.12.3.1. The Code
3.13. Create a Custom Attribute
3.13.1. Problem
3.13.2. Solution
3.13.3. How It Works
3.13.3.1. The Code
3.13.3.2. Usage
3.14. Inspect the Attributes of a Program Element Using Reflection
3.14.1. Problem
3.14.2. Solution
3.14.3. How It Works
3.14.3.1. The Code
3.15. Programmatically Discover the Members of a Type
3.15.1. Problem
3.15.2. Solution
3.15.3. How It Works
3.15.3.1. The Code
3.16. Invoke a Type Member Using Reflection
3.16.1. Problem
3.16.2. Solution
3.16.3. How It Works
3.16.3.1. The Code
3.17. Dynamically Invoke a Type Member
3.17.1. Problem
3.17.2. Solution
3.17.3. How It Works
3.17.3.1. The Code
3.18. Create a Custom Dynamic Type
3.18.1. Problem
3.18.2. Solution
3.18.3. How It Works
3.18.3.1. The Code
4. Threads, Processes, and Synchronization
4.1. Execute a Method Using the Thread Pool
4.1.1. Problem
4.1.2. Solution
4.1.3. How It Works
4.1.3.1. The Code
4.1.4. Notes
4.2. Execute a Method Asynchronously
4.2.1. Problem
4.2.2. Solution
4.2.3. How It Works
4.2.3.1. The Code
4.3. Execute a Method Periodically
4.3.1. Problem
4.3.2. Solution
4.3.3. How It Works
4.3.3.1. The Code
4.4. Execute a Method at a Specific Time
4.4.1. Problem
4.4.2. Solution
4.4.3. How It Works
4.4.3.1. The Code
4.5. Execute a Method by Signaling a WaitHandle Object
4.5.1. Problem
4.5.2. Solution
4.5.3. How It Works
4.5.3.1. The Code
4.6. Execute a Method Using a New Thread
4.6.1. Problem
4.6.2. Solution
4.6.3. How It Works
4.6.3.1. The Code
4.7. Synchronize the Execution of Multiple Threads Using a Monitor
4.7.1. Problem
4.7.2. Solution
4.7.3. How It Works
4.7.3.1. The Code
4.8. Synchronize the Execution of Multiple Threads Using an Event
4.8.1. Problem
4.8.2. Solution
4.8.3. How It Works
4.8.3.1. The Code
4.9. Synchronize the Execution of Multiple Threads Using a Mutex
4.9.1. Problem
4.9.2. Solution
4.9.3. How It Works
4.9.3.1. The Code
4.10. Synchronize the Execution of Multiple Threads Using a Semaphore
4.10.1. Problem
4.10.2. Solution
4.10.3. How It Works
4.10.3.1. The Code
4.11. Synchronize Access to a Shared Data Value
4.11.1. Problem
4.11.2. Solution
4.11.3. How It Works
4.11.3.1. The Code
4.12. Know When a Thread Finishes
4.12.1. Problem
4.12.2. Solution
4.12.3. How It Works
4.12.3.1. The Code
4.13. Terminate the Execution of a Thread
4.13.1. Problem
4.13.2. Solution
4.13.3. How It Works
4.13.3.1. The Code
4.14. Create a Thread-Safe Collection Instance
4.14.1. Problem
4.14.2. Solution
4.14.3. How It Works
4.14.3.1. The Code
4.15. Start a New Process
4.15.1. Problem
4.15.2. Solution
4.15.3. How It Works
4.15.3.1. The Code
4.16. Terminate a Process
4.16.1. Problem
4.16.2. Solution
4.16.3. How It Works
4.16.3.1. The Code
4.17. Ensure That Only One Instance of an Application Can Execute Concurrently
4.17.1. Problem
4.17.2. Solution
4.17.3. How It Works
4.17.3.1. The Code
5. Files, Directories, and I/O
5.1. Retrieve Information About a File, Directory, or Drive
5.1.1. Problem
5.1.2. Solution
5.1.3. How It Works
5.1.3.1. The Code
5.1.3.2. Usage
5.2. Set File and Directory Attributes
5.2.1. Problem
5.2.2. Solution
5.2.3. How It Works
5.2.3.1. The Code
5.3. Copy, Move, or Delete a File or Directory
5.3.1. Problem
5.3.2. Solution
5.3.3. How It Works
5.3.3.1. The Code
5.4. Calculate the Size of a Directory
5.4.1. Problem
5.4.2. Solution
5.4.3. How It Works
5.4.3.1. The Code
5.5. Retrieve Version Information for a File
5.5.1. Problem
5.5.2. Solution
5.5.3. How It Works
5.5.3.1. The Code
5.5.3.2. Usage
5.6. Show a Just-in-Time Directory Tree in the TreeView Control
5.6.1. Problem
5.6.2. Solution
5.6.3. How It Works
5.6.3.1. The Code
5.7. Read and Write a Text File
5.7.1. Problem
5.7.2. Solution
5.7.3. How It Works
5.7.3.1. The Code
5.8. Read and Write a Binary File
5.8.1. Problem
5.8.2. Solution
5.8.3. How It Works
5.8.3.1. The Code
5.9. Read a File Asynchronously
5.9.1. Problem
5.9.2. Solution
5.9.3. How It Works
5.9.3.1. The Code
5.9.3.2. Usage
5.10. Find Files That Match a Wildcard Expression
5.10.1. Problem
5.10.2. Solution
5.10.3. How It Works
5.10.3.1. The Code
5.11. Test Two Files for Equality
5.11.1. Problem
5.11.2. Solution
5.11.3. How It Works
5.11.3.1. The Code
5.12. Manipulate Strings Representing File Names
5.12.1. Problem
5.12.2. Solution
5.12.3. How It Works
5.13. Determine If a Path Is a Directory or a File
5.13.1. Problem
5.13.2. Solution
5.13.3. How It Works
5.13.3.1. The Code
5.14. Work with Relative Paths
5.14.1. Problem
5.14.2. Solution
5.14.3. How It Works
5.14.3.1. The Code
5.14.3.2. Usage
5.15. Create a Temporary File
5.15.1. Problem
5.15.2. Solution
5.15.3. How It Works
5.15.3.1. The Code
5.16. Get the Total Free Space on a Drive
5.16.1. Problem
5.16.2. Solution
5.16.3. How It Works
5.16.3.1. The Code
5.17. Show the Common File Dialog Boxes
5.17.1. Problem
5.17.2. Solution
5.17.3. How It Works
5.17.3.1. The Code
5.18. Use an Isolated Store
5.18.1. Problem
5.18.2. Solution
5.18.3. How It Works
5.18.3.1. The Code
5.19. Monitor the File System for Changes
5.19.1. Problem
5.19.2. Solution
5.19.3. How It Works
5.19.3.1. The Code
5.20. Access a COM Port
5.20.1. Problem
5.20.2. Solution
5.20.3. How It Works
5.20.3.1. The Code
5.21. Get a Random File Name
5.21.1. Problem
5.21.2. Solution
5.21.3. How It Works
5.21.3.1. The Code
5.22. Manipulate the Access Control List of a File or Directory
5.22.1. Problem
5.22.2. Solution
5.22.3. How It Works
5.22.3.1. The Code
5.23. Compress Data
5.23.1. Problem
5.23.2. Solution
5.23.3. How It Works
5.23.3.1. The Code
5.24. Log Data to a File
5.24.1. Problem
5.24.2. Solution
5.24.3. How It Works
5.24.3.1. The Code
5.25. Process a Log File
5.25.1. Problem
5.25.2. Solution
5.25.3. How It Works
5.25.3.1. The Code
5.26. Communicate Between Processes
5.26.1. Problem
5.26.2. Solution
5.26.3. How It Works
5.26.3.1. The Code
6. XML Processing
6.1. Show the Structure of an XML Document in a TreeView
6.1.1. Problem
6.1.2. Solution
6.1.3. How It Works
6.1.3.1. The Code
6.1.3.2. Usage
6.2. Insert Nodes in an XML Document
6.2.1. Problem
6.2.2. Solution
6.2.3. How It Works
6.2.3.1. The Code
6.3. Quickly Append Nodes in an XML Document
6.3.1. Problem
6.3.2. Solution
6.3.3. How It Works
6.3.3.1. The Code
6.4. Find Specific Elements by Name
6.4.1. Problem
6.4.2. Solution
6.4.3. How It Works
6.4.3.1. The Code
6.4.4. Notes
6.5. Get XML Nodes in a Specific XML Namespace
6.5.1. Problem
6.5.2. Solution
6.5.3. How It Works
6.5.3.1. The Code
6.6. Find Elements with an XPath Search
6.6.1. Problem
6.6.2. Solution
6.6.3. How It Works
6.6.3.1. The Code
6.6.4. Notes
6.7. Read and Write XML Without Loading an Entire Document into Memory
6.7.1. Problem
6.7.2. Solution
6.7.2.1. How It Works
6.7.2.2. The Code
6.8. Validate an XML Document Against a Schema
6.8.1. Problem
6.8.2. Solution
6.8.3. How It Works
6.8.3.1. The Code
6.9. Use XML Serialization with Custom Objects
6.9.1. Problem
6.9.2. Solution
6.9.3. How It Works
6.9.3.1. The Code
6.10. Create a Schema for a .NET Class
6.10.1. Problem
6.10.2. Solution
6.10.3. How It Works
6.10.3.1. Usage
6.11. Generate a Class from a Schema
6.11.1. Problem
6.11.2. Solution
6.11.3. How It Works
6.11.3.1. Usage
6.12. Perform an XSL Transform
6.12.1. Problem
6.12.2. Solution
6.12.3. How It Works
6.12.3.1. The Code
6.13. Load XML with LINQ
6.13.1. Problem
6.13.2. Solution
6.13.3. How It Works
6.13.3.1. The Code
6.14. Create a New XML Tree with LINQ
6.14.1. Problem
6.14.2. Solution
6.14.3. How It Works
6.14.3.1. The Code
6.15. Query XML with LINQ
6.15.1. Problem
6.15.2. Solution
6.15.3. How It Works
6.15.3.1. The Code
6.16. Modify an XML Tree with LINQ
6.16.1. The Problem
6.16.2. The Solution
6.16.3. How It Works
6.16.3.1. The Code
7. Windows Forms
7.1. Add a Control Programmatically
7.1.1. Problem
7.1.2. Solution
7.1.3. How It Works
7.1.3.1. The Code
7.2. Store Data with a Control
7.2.1. Problem
7.2.2. Solution
7.2.3. How It Works
7.2.3.1. The Code
7.3. Process All the Controls on a Form
7.3.1. Problem
7.3.2. Solution
7.3.3. How It Works
7.3.3.1. The Code
7.4. Track the Visible Forms in an Application
7.4.1. Problem
7.4.2. Solution
7.4.3. How It Works
7.4.3.1. The Code
7.4.4. Notes
7.5. Find All MDI Child Forms
7.5.1. Problem
7.5.2. Solution
7.5.3. How It Works
7.5.3.1. The Code
7.6. Save Configuration Settings for a Form
7.6.1. Problem
7.6.2. Solution
7.6.3. How It Works
7.6.3.1. The Code
7.7. Force a List Box to Scroll to the Most Recently Added Item
7.7.1. Problem
7.7.2. Solution
7.7.3. How It Works
7.7.3.1. The Code
7.8. Restrict a Text Box to Accept Only Specific Input
7.8.1. Problem
7.8.2. Solution
7.8.3. How It Works
7.8.3.1. The Code
7.8.4. Notes
7.9. Use an Autocomplete Combo Box or Text Box
7.9.1. Problem
7.9.2. Solution
7.9.3. How It Works
7.9.3.1. The Code
7.10. Sort a List View by Any Column
7.10.1. Problem
7.10.2. Solution
7.10.3. How It Works
7.10.3.1. The Code
7.11. Lay Out Controls Automatically
7.11.1. Problem
7.11.2. Solution
7.11.3. How It Works
7.12. Use Part of a Main Menu for a Context Menu
7.12.1. Problem
7.12.2. Solution
7.12.3. How It Works
7.12.3.1. The Code
7.13. Make a Multilingual Form
7.13.1. Problem
7.13.2. Solution
7.13.3. How It Works
7.13.3.1. The Code
7.14. Create a Form That Cannot Be Moved
7.14.1. Problem
7.14.2. Solution
7.14.3. How It Works
7.14.3.1. The Code
7.15. Make a Borderless Form Movable
7.15.1. Problem
7.15.2. Solution
7.15.3. How It Works
7.15.3.1. The Code
7.16. Create an Animated System Tray Icon
7.16.1. Problem
7.16.2. Solution
7.16.3. How It Works
7.16.3.1. The Code
7.17. Validate an Input Control
7.17.1. Problem
7.17.2. Solution
7.17.3. How It Works
7.17.3.1. The Code
7.18. Use a Drag-and-Drop Operation
7.18.1. Problem
7.18.2. Solution
7.18.3. How It Works
7.18.3.1. The Code
7.19. Update the User Interface in a Multithreaded Application
7.19.1. Problem
7.19.2. Solution
7.19.3. How It Works
7.19.3.1. The Code
7.20. Display a Web Page in a Windows-Based Application
7.20.1. Problem
7.20.2. Solution
7.20.3. How It Works
7.20.3.1. The Code
7.21. Display WPF Windows in a Windows Forms Application
7.21.1. Problem
7.21.2. Solution
7.21.3. How It Works
7.21.3.1. The Code
7.22. Display WPF Controls in Windows Forms
7.22.1. Problem
7.22.2. Solution
7.22.3. How It Works
7.22.3.1. The Code
8. Graphics, Multimedia, and Printing
8.1. Find All Installed Fonts
8.1.1. Problem
8.1.2. Solution
8.1.3. How It Works
8.1.3.1. The Code
8.2. Perform Hit Testing with Shapes
8.2.1. Problem
8.2.2. Solution
8.2.3. How It Works
8.2.3.1. The Code
8.3. Create an Irregularly Shaped Control
8.3.1. Problem
8.3.2. Solution
8.3.3. How It Works
8.3.3.1. The Code
8.4. Create a Movable Sprite
8.4.1. Problem
8.4.2. Solution
8.4.3. How It Works
8.4.3.1. The Code
8.5. Create a Scrollable Image
8.5.1. Problem
8.5.2. Solution
8.5.3. How It Works
8.5.3.1. The Code
8.6. Perform a Screen Capture
8.6.1. Problem
8.6.2. Solution
8.6.3. How It Works
8.6.3.1. The Code
8.7. Use Double Buffering to Increase Redraw Speed
8.7.1. Problem
8.7.2. Solution
8.7.3. How It Works
8.7.3.1. The Code
8.8. Show a Thumbnail for an Image
8.8.1. Problem
8.8.2. Solution
8.8.3. How It Works
8.8.3.1. The Code
8.9. Play a Simple Beep or System Sound
8.9.1. Problem
8.9.2. Solution
8.9.3. How It Works
8.9.3.1. The Code
8.10. Play a WAV File
8.10.1. Problem
8.10.2. Solution
8.10.3. How It Works
8.10.3.1. The Code
8.11. Play a Sound File
8.11.1. Problem
8.11.2. Solution
8.11.3. How It Works
8.11.3.1. The Code
8.12. Play a Video
8.12.1. Problem
8.12.2. Solution
8.12.3. How It Works
8.12.3.1. The Code
8.13. Retrieve Information About Installed Printers
8.13.1. Problem
8.13.2. Solution
8.13.3. How It Works
8.13.3.1. The Code
8.13.3.2. Usage
8.14. Print a Simple Document
8.14.1. Problem
8.14.2. Solution
8.14.3. How It Works
8.14.3.1. The Code
8.15. Print a Multipage Document
8.15.1. Problem
8.15.2. Solution
8.15.3. How It Works
8.15.3.1. The Code
8.16. Print Wrapped Text
8.16.1. Problem
8.16.2. Solution
8.16.3. How It Works
8.16.3.1. The Code
8.17. Show a Dynamic Print Preview
8.17.1. Problem
8.17.2. Solution
8.17.3. How It Works
8.17.3.1. The Code
8.18. Manage Print Jobs
8.18.1. Problem
8.18.2. Solution
8.18.3. How It Works
8.18.3.1. The Code
8.19. Perform Text-to-Speech
8.19.1. Problem
8.19.2. Solution
8.19.3. How It Works
8.19.3.1. The Code
8.20. Recognize Characters in an Image (OCR)
8.20.1. Problem
8.20.2. Solution
8.20.3. How It Works
8.20.3.1. The Code
9. Database Access
9.1. Connect to a Database
9.1.1. Problem
9.1.2. Solution
9.1.3. How It Works
9.1.3.1. The Code
9.2. Use Connection Pooling
9.2.1. Problem
9.2.2. Solution
9.2.3. How It Works
9.2.3.1. The Code
9.2.4. Notes
9.3. Create a Database Connection String Programmatically
9.3.1. Problem
9.3.2. Solution
9.3.3. How It Works
9.3.3.1. The Code
9.4. Store a Database Connection String Securely
9.4.1. Problem
9.4.2. Solution
9.4.3. How It Works
9.4.3.1. The Code
9.5. Execute a SQL Command or Stored Procedure
9.5.1. Problem
9.5.2. Solution
9.5.3. How It Works
9.5.3.1. The Code
9.6. Use Parameters in a SQL Command or Stored Procedure
9.6.1. Problem
9.6.2. Solution
9.6.3. How It Works
9.6.3.1. The Code
9.7. Process the Results of a SQL Query Using a Data Reader
9.7.1. Problem
9.7.2. Solution
9.7.3. How It Works
9.7.3.1. The Code
9.8. Obtain an XML Document from a SQL Server Query
9.8.1. Problem
9.8.2. Solution
9.8.3. How It Works
9.8.3.1. The Code
9.9. Perform Asynchronous Database Operations Against SQL Server
9.9.1. Problem
9.9.2. Solution
9.9.3. How It Works
9.9.3.1. The Code
9.10. Write Database-Independent Code
9.10.1. Problem
9.10.2. Solution
9.10.3. How It Works
9.10.3.1. The Code
9.11. Discover All Instances of SQL Server on Your Network
9.11.1. Problem
9.11.2. Solution
9.11.3. How It Works
9.11.3.1. The Code
9.12. Create an In-Memory Cache
9.12.1. Problem
9.12.2. Solution
9.12.3. How It Works
9.12.3.1. The Code
9.13. Create a DataSet Programmatically
9.13.1. Problem
9.13.2. Solution
9.13.3. How It Works
9.13.3.1. The Code
9.14. Perform a LINQ Query
9.14.1. Problem
9.14.2. Solution
9.14.3. How It Works
9.14.3.1. The Code
9.15. Perform a LINQ Query with Entity Types
9.15.1. Problem
9.15.2. Solution
9.15.3. How It Works
9.15.3.1. The Code
9.16. Compare LINQ DataSet Results
9.16.1. Problem
9.16.2. Solution
9.16.3. How It Works
9.16.3.1. The Code
10. Networking
10.1. Obtain Information About the Local Network Interface
10.1.1. Problem
10.1.2. Solution
10.1.3. How It Works
10.1.3.1. The Code
10.2. Detect Changes in Network Connectivity
10.2.1. Problem
10.2.2. Solution
10.2.3. How It Works
10.2.3.1. The Code
10.3. Download Data over HTTP or FTP
10.3.1. Problem
10.3.2. Solution
10.3.3. How It Works
10.3.3.1. The Code
10.3.4. Notes
10.4. Download a File and Process It Using a Stream
10.4.1. Problem
10.4.2. Solution
10.4.3. How It Works
10.4.3.1. The Code
10.5. Respond to HTTP Requests from Within Your Application
10.5.1. Problem
10.5.2. Solution
10.5.3. How It Works
10.5.3.1. The Code
10.6. Get an HTML Page from a Site That Requires Authentication
10.6.1. Problem
10.6.2. Solution
10.6.3. How It Works
10.6.3.1. The Code
10.7. Send E-mail Using SMTP
10.7.1. Problem
10.7.2. Solution
10.7.3. How It Works
10.7.3.1. The Code
10.8. Resolve a Host Name to an IP Address
10.8.1. Problem
10.8.2. Solution
10.8.3. How It Works
10.8.3.1. The Code
10.8.3.2. Usage
10.9. Ping an IP Address
10.9.1. Problem
10.9.2. Solution
10.9.3. How It Works
10.9.3.1. The Code
10.9.3.2. Usage
10.10. Communicate Using TCP
10.10.1. Problem
10.10.2. Solution
10.10.3. How It Works
10.10.3.1. The Code
10.10.3.2. Usage
10.11. Create a Multithreaded TCP Server That Supports Asynchronous Communications
10.11.1. Problem
10.11.2. Solution
10.11.3. How It Works
10.11.3.1. The Code
10.12. Communicate Using UDP
10.12.1. Problem
10.12.2. Solution
10.12.3. How It Works
10.12.3.1. The Code
10.13. Create a SOAP-Based Web Service
10.13.1. Problem
10.13.2. Solution
10.13.3. How It Works
10.13.3.1. The Code
10.14. Call a WCF Service Using a Dynamically Generated Service Proxy
10.14.1. Problem
10.14.2. Solution
10.14.3. How It Works
10.14.3.1. The Code
10.15. Process the Content of an Atom or RSS Feed
10.15.1. Problem
10.15.2. Solution
10.15.3. How It Works
10.15.3.1. The Code
10.16. Manipulate URIs
10.16.1. Problem
10.16.2. Solution
10.16.3. How It Works
10.16.3.1. The Code
11. Security and Cryptography
11.1. Allow Partially Trusted Code to Use Your Strongly Named Assembly
11.1.1. Problem
11.1.2. Solution
11.1.3. How It Works
11.1.3.1. The Code
11.1.4. Notes
11.2. Disable Code Access Security
11.2.1. Problem
11.2.2. Solution
11.2.3. How It Works
11.3. Disable Execution Permission Checks
11.3.1. Problem
11.3.2. Solution
11.3.3. How It Works
11.3.3.1. The Code
11.3.4. Notes
11.4. Ensure the Runtime Grants Specific Permissions to Your Assembly
11.4.1. Problem
11.4.2. Solution
11.4.3. How It Works
11.4.3.1. The Code
11.5. Limit the Permissions Granted to Your Assembly
11.5.1. Problem
11.5.2. Solution
11.5.3. How It Works
11.5.3.1. The Code
11.6. View the Permissions Required by an Assembly
11.6.1. Problem
11.6.2. Solution
11.6.3. How It Works
11.6.3.1. The Code
11.6.3.2. Usage
11.7. Determine at Runtime If Your Code Has a Specific Permission
11.7.1. Problem
11.7.2. Solution
11.7.3. How It Works
11.7.3.1. The Code
11.8. Restrict Who Can Extend Your Classes and Override Class Members
11.8.1. Problem
11.8.2. Solution
11.8.3. How It Works
11.8.3.1. The Code
11.9. Inspect an Assembly's Evidence
11.9.1. Problem
11.9.2. Solution
11.9.3. How It Works
11.9.3.1. The Code
11.10. Determine If the Current User Is a Member of a Specific Windows Group
11.10.1. Problem
11.10.2. Solution
11.10.3. How It Works
11.10.3.1. The Code
11.10.3.2. Usage
11.11. Restrict Which Users Can Execute Your Code
11.11.1. Problem
11.11.2. Solution
11.11.3. How It Works
11.11.3.1. The Code
11.12. Impersonate a Windows User
11.12.1. Problem
11.12.2. Solution
11.12.3. How It Works
11.12.3.1. The Code
11.12.3.2. Usage
11.13. Create a Cryptographically Random Number
11.13.1. Problem
11.13.2. Solution
11.13.3. How It Works
11.13.3.1. The Code
11.14. Calculate the Hash Code of a Password
11.14.1. Problem
11.14.2. Solution
11.14.3. How It Works
11.14.3.1. The Code
11.14.3.2. Usage
11.15. Calculate the Hash Code of a File
11.15.1. Problem
11.15.2. Solution
11.15.3. How It Works
11.15.3.1. The Code
11.15.3.2. Usage
11.16. Verify a Hash Code
11.16.1. Problem
11.16.2. Solution
11.16.3. How It Works
11.16.3.1. The Code
11.17. Ensure Data Integrity Using a Keyed Hash Code
11.17.1. Problem
11.17.2. Solution
11.17.3. How It Works
11.17.3.1. The Code
11.17.3.2. Usage
11.18. Work with Security-Sensitive Strings in Memory
11.18.1. Problem
11.18.2. Solution
11.18.3. How It Works
11.18.3.1. The Code
11.19. Encrypt and Decrypt Data Using the Data Protection API
11.19.1. Problem
11.19.2. Solution
11.19.3. How It Works
11.19.3.1. The Code
12. Unmanaged Code Interoperability
12.1. Call a Function in an Unmanaged DLL
12.1.1. Problem
12.1.2. Solution
12.1.3. How It Works
12.1.3.1. The Code
12.2. Get the Handle for a Control, Window, or File
12.2.1. Problem
12.2.2. Solution
12.2.3. How It Works
12.2.3.1. The Code
12.3. Call an Unmanaged Function That Uses a Structure
12.3.1. Problem
12.3.2. Solution
12.3.3. How It Works
12.3.3.1. The Code
12.4. Call an Unmanaged Function That Uses a Callback
12.4.1. Problem
12.4.2. Solution
12.4.3. How It Works
12.4.3.1. The Code
12.5. Retrieve Unmanaged Error Information
12.5.1. Problem
12.5.2. Solution
12.5.3. How It Works
12.5.3.1. The Code
12.6. Use a COM Component in a .NET Client
12.6.1. Problem
12.6.2. Solution
12.6.3. How It Works
12.6.3.1. The Code
12.7. Release a COM Component Quickly
12.7.1. Problem
12.7.2. Solution
12.7.3. How It Works
12.8. Use Optional Parameters
12.8.1. Problem
12.8.2. Solution
12.8.3. How It Works
12.8.3.1. The Code
12.9. Use an ActiveX Control in a .NET Client
12.9.1. Problem
12.9.2. Solution
12.9.3. How It Works
12.10. Expose a .NET Component Through COM
12.10.1. Problem
12.10.2. Solution
12.10.3. How It Works
13. Commonly Used Interfaces and Patterns
13.1. Implement a Custom Serializable Type
13.1.1. Problem
13.1.2. Solution
13.1.3. How It Works
13.1.3.1. The Code
13.2. Implement a Cloneable Type
13.2.1. Problem
13.2.2. Solution
13.2.3. How It Works
13.2.3.1. The Code
13.3. Implement a Comparable Type
13.3.1. Problem
13.3.2. Solution
13.3.3. How It Works
13.3.3.1. The Code
13.3.3.2. Usage
13.4. Implement an Enumerable Collection
13.4.1. Problem
13.4.2. Solution
13.4.3. How It Works
13.4.3.1. The Code
13.5. Implement an Enumerable Type Using a Custom Iterator
13.5.1. Problem
13.5.2. Solution
13.5.3. How It Works
13.5.3.1. The Code
13.6. Implement a Disposable Class
13.6.1. Problem
13.6.2. Solution
13.6.3. How It Works
13.6.3.1. The Code
13.7. Implement a Formattable Type
13.7.1. Problem
13.7.2. Solution
13.7.3. How It Works
13.7.3.1. The Code
13.7.3.2. Usage
13.8. Implement a Custom Exception Class
13.8.1. Problem
13.8.2. Solution
13.8.3. How It Works
13.8.3.1. The Code
13.9. Implement a Custom Event Argument
13.9.1. Problem
13.9.2. Solution
13.9.3. How It Works
13.9.3.1. The Code
13.10. Implement the Singleton Pattern
13.10.1. Problem
13.10.2. Solution
13.10.3. How It Works
13.10.3.1. The Code
13.10.3.2. Usage
13.11. Implement the Observer Pattern
13.11.1. Problem
13.11.2. Solution
13.11.3. How It Works
13.11.3.1. The Code
13.11.3.2. Usage
13.12. Implement a Parallel Producer-Consumer Pattern
13.12.1. Problem
13.12.2. Solution
13.12.3. How It Works
13.12.3.1. The Code
13.13. Perform Lazy Object Initialization
13.13.1. Problem
13.13.2. Solution
13.13.3. How It Works
13.13.3.1. The Code
13.14. Use Optional Parameters
13.14.1. Problem
13.14.2. Solution
13.14.3. How It Works
13.14.3.1. The Code
13.15. Add a Method to a Type Without Modifying It
13.15.1. Problem
13.15.2. Solution
13.15.3. How It Works
13.15.3.1. The Code
13.16. Call an Object Member Dynamically
13.16.1. Problem
13.16.2. Solution
13.16.3. How It Works
13.16.3.1. The Code
13.17. Create a Variant Generic Type
13.17.1. Problem
13.17.2. Solution
13.17.3. How It Works
13.17.3.1. The Code
14. Windows Integration
14.1. Access Runtime Environment Information
14.1.1. Problem
14.1.2. Solution
14.1.3. How It Works
14.1.3.1. The Code
14.2. Retrieve the Value of an Environment Variable
14.2.1. Problem
14.2.2. Solution
14.2.3. How It Works
14.2.3.1. The Code
14.3. Write an Event to the Windows Event Log
14.3.1. Problem
14.3.2. Solution
14.3.3. How It Works
14.3.3.1. The Code
14.4. Read and Write to the Windows Registry
14.4.1. Problem
14.4.2. Solution
14.4.3. How It Works
14.4.3.1. The Code
14.5. Search the Windows Registry
14.5.1. Problem
14.5.2. Solution
14.5.3. How It Works
14.5.3.1. The Code
14.5.3.2. Usage
14.6. Create a Windows Service
14.6.1. Problem
14.6.2. Solution
14.6.3. How It Works
14.6.3.1. The Code
14.6.3.2. Usage
14.7. Create a Windows Service Installer
14.7.1. Problem
14.7.2. Solution
14.7.3. How It Works
14.7.3.1. The Code
14.7.3.2. Usage
14.8. Create a Shortcut on the Desktop or Start Menu
14.8.1. Problem
14.8.2. Solution
14.8.3. How It Works
14.8.3.1. The Code
14.9. Create a Windows 7 Jump List
14.9.1. Problem
14.9.2. Solution
14.9.3. How It Works
14.9.3.1. The Code
14.10. Use Windows Search
14.10.1. Problem
14.10.2. Solution
14.10.3. How It Works
14.10.3.1. The Code
14.11. Check Internet Connectivity
14.11.1. Problem
14.11.2. Solution
14.11.3. How It Works
14.11.3.1. The Code
14.12. Display a Task Dialog
14.12.1. Problem
14.12.2. Solution
14.12.3. How It Works
14.12.3.1. The Code
14.13. Write Custom Performance Counters
14.13.1. Problem
14.13.2. Solution
14.13.3. How It Works
14.13.3.1. The Code
14.14. Read Performance Counters
14.14.1. Problem
14.14.2. Solution
14.14.3. How It Works
14.14.3.1. The Code
14.15. Obtain Elevated Privileges
14.15.1. Problem
14.15.2. Solution
14.15.3. How It Works
14.15.3.1. The Code
15. Parallel Programming
15.1. Perform Simple Parallel Tasks
15.1.1. Problem
15.1.2. Solution
15.1.3. How It Works
15.1.3.1. The Code
15.2. Return a Result from a Task
15.2.1. Problem
15.2.2. Solution
15.2.3. How It Works
15.2.3.1. The Code
15.3. Wait for Tasks to Complete
15.3.1. Problem
15.3.2. Solution
15.3.3. How It Works
15.3.3.1. The Code
15.4. Parallel Process a Collection
15.4.1. Problem
15.4.2. Solution
15.4.3. How It Works
15.4.3.1. The Code
15.5. Chain Tasks Together
15.5.1. Problem
15.5.2. Solution
15.5.3. How It Works
15.5.3.1. The Code
15.6. Write a Cooperative Algorithm
15.6.1. Problem
15.6.2. Solution
15.6.3. How It Works
15.6.3.1. The Code
15.7. Handle Exceptions in Tasks
15.7.1. Problem
15.7.2. Solution
15.7.3. How It Works
15.7.3.1. The Code
15.8. Cancel a Task
15.8.1. Problem
15.8.2. Solution
15.8.3. How It Works
15.8.3.1. The Code
15.9. Share Data Between Tasks
15.9.1. Problem
15.9.2. Solution
15.9.3. How It Works
15.9.3.1. The Code
16. Using LINQ
16.1. Perform a Simple LINQ Query
16.1.1. Problem
16.1.2. Solution
16.1.3. How It Works
16.1.3.1. The Code
16.2. Filter Items from a Data Source
16.2.1. Problem
16.2.2. Solution
16.2.3. How It Works
16.2.3.1. The Code
16.3. Filter a Data Source by Type
16.3.1. Problem
16.3.2. Solution
16.3.3. How It Works
16.3.3.1. The Code
16.4. Filter Ranges of Elements
16.4.1. Problem
16.4.2. Solution
16.4.3. How It Works
16.4.3.1. The Code
16.5. Select Multiple Member Values
16.5.1. Problem
16.5.2. Solution
16.5.3. How It Works
16.5.3.1. The Code
16.6. Filter and Select from Multiple Data Sources
16.6.1. Problem
16.6.2. Solution
16.6.3. How It Works
16.6.3.1. The Code
16.7. Use Permutations of Data Sources
16.7.1. Problem
16.7.2. Solution
16.7.3. How It Works
16.7.3.1. The Code
16.8. Concatenate Data Sources
16.8.1. Problem
16.8.2. Solution
16.8.3. How It Works
16.8.3.1. The Code
16.9. Group Result Elements by Attribute
16.9.1. Problem
16.9.2. Solution
16.9.3. How It Works
16.9.3.1. The Code
16.10. Sort Query Results
16.10.1. Problem
16.10.2. Solution
16.10.3. How It Works
16.10.3.1. The Code
16.11. Compare Data Sources
16.11.1. Problem
16.11.2. The Solution
16.11.3. How It Works
16.11.3.1. The Code
16.12. Aggregate Data Sources
16.12.1. Problem
16.12.2. Solution
16.12.3. How It Works
16.12.3.1. The Code
16.13. Share Values Within a Query
16.13.1. Problem
16.13.2. Solution
16.13.3. How It Works
16.13.3.1. The Code
16.14. Create Custom LINQ Extension Methods
16.14.1. Problem
16.14.2. Solution
16.14.3. How It Works
16.14.3.1. The Code
16.15. Convert from IEnumerable<>
16.15.1. Problem
16.15.2. Solution
16.15.3. How It Works
16.15.3.1. The Code
17. Windows Presentation Foundation
17.1. Create and Use a Dependency Property
17.1.1. Problem
17.1.2. Solution
17.1.3. How It Works
17.1.3.1. The Code
17.2. Create and Use an Attached Property
17.2.1. Problem
17.2.2. Solution
17.2.3. How It Works
17.2.3.1. The Code
17.3. Define Application-Wide Resources
17.3.1. Problem
17.3.2. Solution
17.3.3. How It Works
17.3.3.1. The Code
17.4. Debug Data Bindings Using an IValueConverter
17.4.1. Problem
17.4.2. Solution
17.4.3. How It Works
17.4.3.1. The Code
17.5. Debug Bindings Using Attached Properties
17.5.1. Problem
17.5.2. Solution
17.5.3. How It Works
17.5.3.1. The Code
17.6. Arrange UI Elements in a Horizontal or Vertical Stack
17.6.1. Problem
17.6.2. Solution
17.6.3. How It Works
17.6.3.1. The Code
17.7. Dock UI Elements to the Edges of a Form
17.7.1. Problem
17.7.2. Solution
17.7.3. How It Works
17.7.3.1. The Code
17.8. Arrange UI Elements in a Grid
17.8.1. Problem
17.8.2. Solution
17.8.3. How It Works
17.8.3.1. The Code
17.9. Position UI Elements Using Exact Coordinates
17.9.1. Problem
17.9.2. Solution
17.9.3. How It Works
17.9.3.1. The Code
17.10. Get Rich Text Input from a User
17.10.1. Problem
17.10.2. Solution
17.10.3. How It Works
17.10.3.1. The Code
17.11. Display a Control Rotated
17.11.1. Problem
17.11.2. Solution
17.11.3. How It Works
17.11.3.1. The Code
17.12. Create a User Control
17.12.1. Problem
17.12.2. Solution
17.12.3. How It Works
17.12.3.1. The Code
17.13. Support Application Commands in a User Control
17.13.1. Problem
17.13.2. Solution
17.13.3. How It Works
17.13.3.1. The Code
17.14. Create a Lookless Custom Control
17.14.1. Problem
17.14.2. Solution
17.14.3. How It Works
17.14.3.1. The Code
17.15. Create a Two-Way Binding
17.15.1. Problem
17.15.2. Solution
17.15.3. How It Works
17.15.3.1. The Code
17.16. Bind to a Command
17.16.1. Problem
17.16.2. Solution
17.16.3. How It Works
17.16.3.1. The Code
17.17. Use Data Templates to Display Bound Data
17.17.1. Problem
17.17.2. Solution
17.17.3. How It Works
17.17.3.1. The Code
17.18. Bind to a Collection with the Master-Detail Pattern
17.18.1. Problem
17.18.2. Solution
17.18.3. How It Works
17.18.3.1. The Code
17.19. Change a Control's Appearance on Mouseover
17.19.1. Problem
17.19.2. Solution
17.19.3. How It Works
17.19.3.1. The Code
17.20. Change the Appearance of Alternate Itemsin a List
17.20.1. Problem
17.20.2. Solution
17.20.3. How It Works
17.20.3.1. The Code
17.21. Drag Items from a List and Drop Them onaCanvas
17.21.1. Problem
17.21.2. Solution
17.21.3. How It Works
17.21.3.1. The Code
17.22. Display the Progress of a Long-Running Operation and Allow the User to Cancel It
17.22.1. Problem
17.22.2. Solution
17.22.3. How It Works
17.22.3.1. The Code
17.23. Draw Two-Dimensional Shapes
17.23.1. Problem
17.23.2. Solution
17.23.3. How It Works
17.23.3.1. The Code
17.24. Create Reusable Shapes
17.24.1. Problem
17.24.2. Solution
17.24.3. How It Works
17.24.3.1. The Code
17.25. Draw or Fill a Shape Using a Solid Color
17.25.1. Problem
17.25.2. Solution
17.25.3. How It Works
17.25.3.1. The Code
17.26. Fill a Shape with a Linear or Radial Color Gradient
17.26.1. Problem
17.26.2. Solution
17.26.3. How It Works
17.26.3.1. The Code
17.27. Fill a Shape with an Image
17.27.1. Problem
17.27.2. Solution
17.27.3. How It Works
17.27.3.1. The Code
17.28. Fill a Shape with a Pattern or Texture
17.28.1. Problem
17.28.2. Solution
17.28.3. How It Works
17.28.3.1. The Code
17.29. Animate the Property of a Control
17.29.1. Problem
17.29.2. Solution
17.29.3. How It Works
17.29.3.1. The Code
17.30. Animate Several Properties in Parallel
17.30.1. Problem
17.30.2. Solution
17.30.3. How It Works
17.30.3.1. The Code
17.31. Create a Keyframe-Based Animation
17.31.1. Problem
17.31.2. Solution
17.31.3. How It Works
17.31.3.1. The Code
17.32. Animate an Object Along a Path
17.32.1. Problem
17.32.2. Solution
17.32.3. How It Works
17.32.3.1. The Code
17.33. Play a Media File
17.33.1. Problem
17.33.2. Solution
17.33.3. How It Works
17.33.3.1. The Code
17.34. Query Keyboard State
17.34.1. Problem
17.34.2. Solution
17.34.3. How It Works
17.34.3.1. The Code
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Copyright
Next
Next Chapter
About the Technical Reviewer
About the Authors
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset