Working with Tasks

   

Working with Tasks

One of the most exciting IDE enhancements from previous versions of Visual Studio, in my opinion, is the new Task List. Tasks are really all about managing code. If your Task List window isn't displayed, show it now by choosing Show Tasks from the View menu and then choosing All. Tasks are used to keep track of critical spots in code or things that need to be done. C# automatically creates some tasks for you, and you can create your own as needed.

One instance in which C.htm# creates tasks is when your code has compile (build) errors. Because C# knows the exact error and the offending statement, it creates an appropriate task. Figure 11.10 shows the Task List containing a build error. Notice how the task's description tells you the exact problem. Double-clicking a system-generated task takes you directly to the related statement (double-clicking a task that you created has a different effect, as discussed shortly). If the task exists in a class that isn't loaded, C# loads the class and then takes you to the statement. This greatly simplifies the process of addressing compile errors in code; you can simply work through the list of tasks rather than compile, fix an error, try compiling again, fix the next error, and so on.

Figure 11.10. Tasks help you keep track of critical spots in code.

graphics/11fig10.jpg


In addition to system-generated tasks, you can create your own tasks as often and wherever needed. In the past, it was common to place certain comments such as "TODO" in code where you needed to address something. These comments often were forgotten. When you wanted to address the issues, you had to perform a text search in your code. This was a highly inefficient process.

Now you can create a task wherever you need to. Creating a task is easy. Right-click the code statement to which you want to attach the task and choose Add Task List Shortcut from the context menu. C# creates a task shortcut at the statement (as indicated by a blue arrow in the left margin of the code window) and adds the task to the Task List window. The default description for the next task is the actual code statement you flagged (see Figure 11.11). To change this text, click the description in the Task List to put it in Edit mode and then change the text. To go directly to the statement to which a task is attached, double-click the shortcut arrow next to the task in the Task List (the arrow is the same one that appears in the left margin of the code window).

Figure 11.11. Tasks make it easy to track issues that need to be addressed.

graphics/11fig11.jpg


graphics/bookpencil.gif

Another way to create a task is to insert a comment that literally starts with TODO: ”Visual Studio .NET will then automatically create a task using the comment.

You don't have to attach a task to a code statement. To create a task that isn't attached to code, click the first row of the Task List. The default text Click here to add a new task goes away, and you're free to enter the description for your new task.

To delete a task you created, click once on the task in the Task List to select it, and then right-click the task and choose Delete from the context menu. You can't delete a task that was created by C# as a result of a build error ”you must correct the error to make the task go away.

Tasks are an incredibly simple, yet useful, tool. I highly encourage you to use them in your development.


   
Top


Sams Teach Yourself C# in 24 Hours
Sams Teach Yourself Visual Basic 2010 in 24 Hours Complete Starter Kit (Sams Teach Yourself -- Hours)
ISBN: 0672331136
EAN: 2147483647
Year: 2002
Pages: 253
Authors: James Foxall

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