Answers to Self Review Exercises


a) Enter, Exit. b) timeslice or quantum. c) garbage collector. d) waiting, sleeping, suspended, blocked for input/output. e) Stopped. f) Lowest, BelowNormal, Normal, AboveNormal, Highest. g) Sleep. h) Pulse. i) lock. j) synchronize.


a) True. b) True. c) False. The code that a thread executes is defined in the method specified by the thread's ThreadStart delegate. d) False. A thread may be in the WaitSleepJoin state for several reasons. Calling Pulse moves a thread from the WaitSleepJoin state to the Running state only if the thread entered the WaitSleepJoin state as the result of a call to Monitor method Wait. e) true. f) False. A thread is blocked by the operating system and returns to the Running state when the operating system determines that the thread can continue executing (e.g., when an I/O request completes or when a lock the thread attempted to acquire becomes available). g) False. Class Monitor methods can be called only if the thread performing the call currently owns the lock on the object each method receives as an argument. h) False. A lock block implicitly relinquishes the lock when the thread completes execution of the lock block. i) True.



(Bouncing Ball) Write a program that bounces a blue ball inside a Panel. The ball should begin moving with a MouseClick event. When the ball hits the edge of the Panel, it should bounce off the edge and continue in the opposite direction. The ball's position should be updated using a THRead and redrawn periodically using another THRead. Use float variables to maintain the ball's position, radius and velocity. Draw the ball using the FillEllipse method of class Graphics (see Fig. 13.38). Remember to terminate all Threads when the user closes the application.


(Enhanced Bouncing Ball) Modify the program in Exercise 15.3 to add a new ball each time the user clicks the mouse. Provide for a maximum of 10 balls. Use a separate THRead to control the movements of each ball, plus an additional Thread to periodically redraw all of the balls. Randomly choose the color and size for each new ball.


(Bouncing Balls with Shadows) Modify the program in Exercise 15.4 to add shadows. As a ball moves, draw a solid black oval at the bottom of the Panel. You may consider adding a 3-D effect by increasing or decreasing the size of the shadow depending upon the vertical position of the ball.


(Bouncing Balls with Collision Detection) Modify the program in Exercise 15.4 or Exercise 15.5 to bounce the balls off each other when they collide. A collision should occur between two balls when the distance between the centers of those two balls is less than the sum of the two balls' radii. When a collision between two balls occurs, use the following equations to modify each ball's velocity:

overlap = ( radius1 + radius2 ) distance

xVelocity1 = xVelocity1 + ( x1 x2 ) * ( overlap / distance ) * 0.5

yVelocity1 = yVelocity1 + ( y1 y2 ) * ( overlap / distance ) * 0.5

xVelocity2 = xVelocity2 + ( x2 x1 ) * ( overlap / distance ) * 0.5

yVelocity2 = yVelocity2 + ( y2 y1 ) * ( overlap / distance ) * 0.5

[Note: Ensure that distance does not equal zero.]

Strings, Characters and Regular Expressions



    Introduction to Computers, the Internet and Visual C#

    Introduction to the Visual C# 2005 Express Edition IDE

    Introduction to C# Applications

    Introduction to Classes and Objects

    Control Statements: Part 1

    Control Statements: Part 2

    Methods: A Deeper Look


    Classes and Objects: A Deeper Look

    Object-Oriented Programming: Inheritance

    Polymorphism, Interfaces & Operator Overloading

    Exception Handling

    Graphical User Interface Concepts: Part 1

    Graphical User Interface Concepts: Part 2


    Strings, Characters and Regular Expressions

    Graphics and Multimedia

    Files and Streams

    Extensible Markup Language (XML)

    Database, SQL and ADO.NET

    ASP.NET 2.0, Web Forms and Web Controls

    Web Services

    Networking: Streams-Based Sockets and Datagrams

    Searching and Sorting

    Data Structures



    Appendix A. Operator Precedence Chart

    Appendix B. Number Systems

    Appendix C. Using the Visual Studio 2005 Debugger

    Appendix D. ASCII Character Set

    Appendix E. Unicode®

    Appendix F. Introduction to XHTML: Part 1

    Appendix G. Introduction to XHTML: Part 2

    Appendix H. HTML/XHTML Special Characters

    Appendix I. HTML/XHTML Colors

    Appendix J. ATM Case Study Code

    Appendix K. UML 2: Additional Diagram Types

    Appendix L. Simple Types


    Visual C# How to Program
    Visual C# 2005 How to Program (2nd Edition)
    ISBN: 0131525239
    EAN: 2147483647
    Year: 2004
    Pages: 600

    Flylib.com © 2008-2020.
    If you may any questions please contact us: flylib@qtcs.net