You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/tutorials/console-teleprompter.md
+24-13Lines changed: 24 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,22 @@ There are a lot of features in this tutorial. Let's build them one by one.
25
25
26
26
## Create the app
27
27
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.
29
44
30
45
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.
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.
203
218
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
-
206
219
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:
207
220
208
221
```csharp
222
+
usingstaticSystem.Math;
223
+
209
224
namespaceTeleprompterConsole;
210
225
211
226
internalclassTelePrompterConfig
@@ -225,17 +240,13 @@ internal class TelePrompterConfig
225
240
}
226
241
```
227
242
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
231
246
enclosing class or namespace names. A [`using static`](../language-reference/keywords/using-directive.md) statement imports the
232
247
methods from one class. This is in contrast with the `using` statement without `static`, which imports all classes from a namespace.
233
248
234
-
```csharp
235
-
usingstaticSystem.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:
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.
252
263
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:
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`:
0 commit comments