1
00:00:00,840 --> 00:00:03,020
So, let's talk about multitasking within

2
00:00:03,020 --> 00:00:07,080
PowerShell. While PowerShell is a

3
00:00:07,080 --> 00:00:11,580
single‑threaded application, it cannot

4
00:00:11,580 --> 00:00:14,460
start running another command in the same

5
00:00:14,460 --> 00:00:18,540
console until the first one finishes, and

6
00:00:18,540 --> 00:00:21,260
you need to make the decision up front to

7
00:00:21,260 --> 00:00:24,300
move to a long‑running command instead of

8
00:00:24,300 --> 00:00:26,490
just trying to inject other things into

9
00:00:26,490 --> 00:00:30,180
the pipeline. Now it's important to

10
00:00:30,180 --> 00:00:31,650
understand the difference between

11
00:00:31,650 --> 00:00:36,560
asynchronous and synchronous. For

12
00:00:36,560 --> 00:00:39,760
asynchronous and synchronous, first off,

13
00:00:39,760 --> 00:00:42,250
PowerShell runs normal commands

14
00:00:42,250 --> 00:00:44,690
synchronously, meaning that when you hit

15
00:00:44,690 --> 00:00:47,950
Return, you then have to wait for that

16
00:00:47,950 --> 00:00:51,730
command to complete. If you move the job

17
00:00:51,730 --> 00:00:54,850
into a background job, it allows it to run

18
00:00:54,850 --> 00:00:57,100
asynchronously, meaning that you can

19
00:00:57,100 --> 00:01:00,860
continue to use the shell for other tasks

20
00:01:00,860 --> 00:01:05,560
while that other command completes. When

21
00:01:05,560 --> 00:01:08,380
we think of synchronous commands, it

22
00:01:08,380 --> 00:01:11,280
allows you to respond to specific input

23
00:01:11,280 --> 00:01:15,660
requests. It will produce error messages

24
00:01:15,660 --> 00:01:17,270
when something goes wrong that you can

25
00:01:17,270 --> 00:01:21,150
visibly see. It will also display results

26
00:01:21,150 --> 00:01:23,380
as soon as they become available, so if

27
00:01:23,380 --> 00:01:24,910
you're querying something, you'll get

28
00:01:24,910 --> 00:01:27,190
results back. And then, of course, it can

29
00:01:27,190 --> 00:01:29,820
prompt you for any missing information

30
00:01:29,820 --> 00:01:34,150
that was required for that command. On the

31
00:01:34,150 --> 00:01:36,360
flip side of this, when using asynchronous

32
00:01:36,360 --> 00:01:39,500
commands, you are not allowed to see any

33
00:01:39,500 --> 00:01:42,950
of the input requests. It can produce

34
00:01:42,950 --> 00:01:45,610
error messages, but you are often unable

35
00:01:45,610 --> 00:01:49,460
to see them. It will display results at

36
00:01:49,460 --> 00:01:53,000
the end of the running task. And there's

37
00:01:53,000 --> 00:01:55,740
no prompt for any missing information, the

38
00:01:55,740 --> 00:02:00,590
command itself will just fail. So what are

39
00:02:00,590 --> 00:02:02,540
the options for multitasking or

40
00:02:02,540 --> 00:02:05,180
multithreading? Well, the first one here

41
00:02:05,180 --> 00:02:08,390
is background job, which is what we're

42
00:02:08,390 --> 00:02:11,060
going to focus on. The second is a

43
00:02:11,060 --> 00:02:13,290
PowerShell runspace. Now we're not going

44
00:02:13,290 --> 00:02:17,000
to talk about those too much in this one, we'll just focus on background jobs.

