DynamoDS/Dynamo — pull request #2376 by Benglin (2014-09-10 07:41:02+00:00)
Title: Replaced IdlePromise with Scheduler Task

Background
-----
This pull request represents the latest instalment for Dynamo Scheduler work. It adds on to the work in [a previous pull request](https://github.com/DynamoDS/Dynamo/pull/2277) by updating ```IdlePromise``` related code to schedule ```DelegateBasedAsyncTask``` through the underlying ```DynamoScheduler```.

Changes
-----
The following changes are included in this pull request (note that the following will be compiled only if ```ENABLE_DYNAMO_SCHEDULER``` is defined):

1. ```RevitServices.Threading.IdlePromise``` has been moved from ```RevitServices``` to ```DynamoRevit``` project.

2. The new ```IdlePromise``` stub class serves as a placeholder to avoid large code changes in other areas that make use of the old ```IdlePromise```.

3. ```DynamoRevit.OnRevitIdleOnce``` method is introduced to set up ```RevitDynamoModel``` and consequently, its internal ```RevitSchedulerThread```.

4. ```RevitDynamoRunner.Evaluate``` method is not implemented in the scheduler world, since ```DynamoRunner``` will be made obsolete and removed.

5. ```DocumentManager.Regenerate``` now assumes its callers to only call it in idle thread. Now it makes direct calls to ```EnsureInTransaction``` and ```ForceCloseTransaction```.

Pending Changes
-----
The following changes will be worked on in immediate submissions:

1. Shutdown logic needs to have their equivalents in the new scheduler world. For now, both ```ExecuteOnShutdown``` and ```Shutdown``` methods on stub class ```IdlePromise``` are not implemented.

2. Update of other consumer of ```IdlePromise``` to use ```DelegateBasedAsyncTask``` directly and remove ```IdlePromise``` completely.

Testing Scenarios
-----
This work is tested with the following scenarios (for a start):

1. Created a series of ```ReferencePoint``` objects in ```Revit 2015```.

2. More test under way...

Notes to Reviewers
-----
Hi @ikeough, please take a look.

This pull request is by no means complete (as far as Revit is concerned), but it contains majority of the changes that get us there. The new code is by default disabled through the use of ```ENABLE_DYNAMO_SCHEDULER``` preprocessor, so it can be safely merged into ```master``` branch.

To enable the scheduler, simply define ```ENABLE_DYNAMO_SCHEDULER``` (under ```Build``` settings in ```Conditional compilation symbols```) for the following projects:

```
- DynamoCore
- DynamoRevit
- RevitServices
```