User Controls Web User Controls Multithreading Immediate Solutions: Using the ScrollableControl Class Using the ContainerControl Class Using the System.Windows.Forms.UserControl Class Creating User Controls Adding Properties to User Controls Adding Methods to User Controls Adding Events to User Controls Testing User Controls Using the TemplateControl Class Using the System.Web.UI.UserControl Class Creating Web User Controls Adding Properties to Web User Controls Adding Methods to Web User Controls Adding Events to Web User Controls Testing Web User Controls Using the Thread Class Creating Threads Starting Threads Suspending Threads Resuming Threads Stopping Threads Sleeping Threads Setting Thread Priority Synchronizing Threads Using SyncLock to Synchronize Threads Joining Threads
In this chapter, we'll work with user controls, Web user controls, and multithreading. User controls are those controls you can build yourself for use in Windows forms, if, for example, you want to create an alarm clock or a stock ticker. Web user controls are the same, but for Web forms. Multithreading gives your programs the ability to do several things at once; each stream of execution is called a thread. When you create new threads in a program, those threads can execute code you give them in the background, no matter what the user is doing with the user interface. Multithreading is often used for lengthy tasks that would otherwise make your program seem to hang. For example, your program may maintain a large database, and it can use a thread in the background to sort that database while the user can get on with other work. I'll take a look at the topics in this chapter—user controls, Web user controls, and multithreading—now, in more depth.