Fix MAGN-3785  Dynamo hangs after running Sample "Ref Grid Sliders"

@lukechurch, @ikeough

There are two threads which are causing a deaklock. The main thread is waiting for a lock on RenderPackagesMutex to be released. Because the main thread is blocked, the process will never be taken as idle. The other thread which is locking RenderPackagesMutex is waiting for some tasks to be done when the process is idle.

The fix here is to minimize the lock scope for the second thread so that when it is locking RenderPackagesMutex, it will not wait for some tasks to be done when the process is idle.

I have not written a test case for this  because this defect can only be randomly reproduced.