Skip to content

Commit fee9fe7

Browse files
CopilotBillWagnerIEvangelist
authored
Improve clarity and user guidance in the Teleprompter Console App tutorial (#47137)
* Initial plan * Implement teleprompter tutorial improvements per issue #25876 Co-authored-by: BillWagner <[email protected]> * Update docs/csharp/tutorials/console-teleprompter.md * Remove directional reference in teleprompter tutorial Co-authored-by: BillWagner <[email protected]> * Update docs/csharp/tutorials/console-teleprompter.md Co-authored-by: David Pine <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: Bill Wagner <[email protected]> Co-authored-by: David Pine <[email protected]>
1 parent b30aef3 commit fee9fe7

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

docs/csharp/tutorials/console-teleprompter.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ There are a lot of features in this tutorial. Let's build them one by one.
2525

2626
## Create the app
2727

28-
The first step is to create a new application. Open a command prompt and create a new directory for your application. Make that the current directory. Type the command `dotnet new console` at the command prompt. This creates the starter files for a basic "Hello World" application.
28+
The first step is to create a new application. Open a command prompt and create a new directory for your application. Make that the current directory. Type the command `dotnet new console` at the command prompt. For example:
29+
30+
```console
31+
E:\development\VSprojects>mkdir teleprompter
32+
E:\development\VSprojects>cd teleprompter
33+
E:\development\VSprojects\teleprompter>dotnet new console
34+
The template "Console Application" was created successfully.
35+
36+
Processing post-creation actions...
37+
Running 'dotnet restore' on E:\development\VSprojects\teleprompter\teleprompter.csproj...
38+
Determining projects to restore...
39+
Restored E:\development\VSprojects\teleprompter\teleprompter.csproj (in 78 ms).
40+
Restore succeeded.
41+
```
42+
43+
This creates the starter files for a basic "Hello World" application.
2944

3045
Before you start making modifications, let's run the simple Hello World application. After creating the application, type `dotnet run` at the command prompt. This command runs the NuGet package restore process, creates the application executable, and runs the executable.
3146

@@ -201,11 +216,11 @@ private static async Task GetInput()
201216

202217
This creates a lambda expression to represent an <xref:System.Action> delegate that reads a key from the Console and modifies a local variable representing the delay when the user presses the '<' (less than) or '>' (greater than) keys. The delegate method finishes when user presses the 'X' or 'x' keys, which allow the user to stop the text display at any time. This method uses <xref:System.Console.ReadKey> to block and wait for the user to press a key.
203218

204-
To finish this feature, you need to create a new `async Task` returning method that starts both of these tasks (`GetInput` and `ShowTeleprompter`), and also manages the shared data between these two tasks.
205-
206219
It's time to create a class that can handle the shared data between these two tasks. This class contains two public properties: the delay, and a flag `Done` to indicate that the file has been completely read:
207220

208221
```csharp
222+
using static System.Math;
223+
209224
namespace TeleprompterConsole;
210225

211226
internal class TelePrompterConfig
@@ -225,17 +240,13 @@ internal class TelePrompterConfig
225240
}
226241
```
227242

228-
Put that class in a new file, and include that class in the
229-
`TeleprompterConsole` namespace as shown. You'll also need to add a `using static`
230-
statement at the top of the file so that you can reference the `Min` and `Max` methods without the
243+
Create a new file; it can be any name ending with .cs. For example TelePrompterConfig.cs. Paste in the TelePrompterConfig class code, save and close. Put that class in the
244+
`TeleprompterConsole` namespace as shown. Note the `using static`
245+
statement allows you to reference the `Min` and `Max` methods without the
231246
enclosing class or namespace names. A [`using static`](../language-reference/keywords/using-directive.md) statement imports the
232247
methods from one class. This is in contrast with the `using` statement without `static`, which imports all classes from a namespace.
233248

234-
```csharp
235-
using static System.Math;
236-
```
237-
238-
Next, you need to update the `ShowTeleprompter` and `GetInput` methods to use the new `config` object. Write one final `Task` returning `async` method to start both tasks and exit when the first task finishes:
249+
Next, you need to update the `ShowTeleprompter` and `GetInput` methods to use the new `config` object. To finish this feature, you need to create a new `async Task` returning method that starts both of these tasks (`GetInput` and `ShowTeleprompter`), and also manages the shared data between these two tasks. Create a RunTelePrompter task to start both tasks and exit when the first task finishes:
239250

240251
```csharp
241252
private static async Task RunTeleprompter()
@@ -250,7 +261,7 @@ private static async Task RunTeleprompter()
250261

251262
The one new method here is the <xref:System.Threading.Tasks.Task.WhenAny(System.Threading.Tasks.Task[])> call. That creates a `Task` that finishes as soon as any of the tasks in its argument list completes.
252263

253-
Next, you need to update both the `ShowTeleprompter` and `GetInput` methods to use the `config` object for the delay:
264+
Next, you need to update both the `ShowTeleprompter` and `GetInput` methods to use the `config` object for the delay. The config object is being passed as a parameter to these methods. Use copy/paste to completely replace the methods with the new code here. You can see the code is using attributes and calling methods from the config object:
254265

255266
```csharp
256267
private static async Task ShowTeleprompter(TelePrompterConfig config)
@@ -285,7 +296,7 @@ private static async Task GetInput(TelePrompterConfig config)
285296
}
286297
```
287298

288-
This new version of `ShowTeleprompter` calls a new method in the `TeleprompterConfig` class. Now, you need to update `Main` to call `RunTeleprompter` instead of `ShowTeleprompter`:
299+
Now, you need to update `Main` to call `RunTeleprompter` instead of `ShowTeleprompter`:
289300

290301
```csharp
291302
await RunTeleprompter();

0 commit comments

Comments
 (0)