Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a C# Task actually start?

When does a Task actually start?

public void DoSomething() {     Task myTask = DoSomethingAsync();      Task.WaitAll(new[] { myTask }, 2000); }  public async Task DoSomethingAsync() {     await SomethingElse(); } 

Does it start immediately when initializing it in Task myTask = DoSomethingAsync(); or does it start when you say to wait for it in Task.WaitAll(new[] { myTask }, 2000); ?

like image 737
GTHvidsten Avatar asked Mar 29 '17 09:03

GTHvidsten


People also ask

How often should AC turn on and off?

Ideally, a properly operating air conditioner should cycle for roughly 15 to 20 minutes, two to three times per hour. If the temperature inside your home is very high, is much higher than the temperature that your thermostat is set at, or the outside temperature is very high, the run time will increase.

Is AC for winter and summer?

Hot and cold air conditioners can regulate the temperature according to your liking, both in summers and winters. The air conditioner simply reverses its function, allowing the AC to run efficiently during winters, thus throwing warm air in the room.

When should the AC be turned on?

As a general rule of thumb, wait for the first stretch of 70 degrees + weather to hit the area. This is when you'll turn on your AC for the first time. However, you're not doing so because you necessarily need to cool down your home.

At what temperature AC is cold?

If you're setting your air conditioner in cooling mode, doing so at lower than 21C will normally be regarded as too cold to have much impact and is generally wasteful of electricity.


1 Answers

Calling an async method returns a hot task, a task that has already been started. So there is no actual code necessary to force it to run.

According MSDN (thanks to Stephen Cleary) the Task-based Asynchronous Pattern (TAP) pattern requires returned tasks to be hot. That means that all tasks, except those created with new Task will be hot.

From the referenced article:

Tasks that are created by the public Task constructors are referred to as cold tasks... All other tasks begin their life cycle in a hot state.

like image 59
Patrick Hofman Avatar answered Oct 06 '22 02:10

Patrick Hofman