@@ -190,23 +190,29 @@ namespace rec Microsoft.VisualStudio.FSharp.ProjectSystem
190190// FSI-LINKAGE-POINT: unsited init
191191do Microsoft.VisualStudio.FSharp.Interactive.Hooks.fsiConsoleWindowPackageCtorUnsited( this:> Package)
192192
193- let mutable mgr : IOleComponentManager = null
193+ // Get the ComponentManager one time at the start
194+ let mgr : IOleComponentManager = this.GetService( typeof< SOleComponentManager>) :?> IOleComponentManager
195+
194196let mutable componentID = 0 u
195197
196- let locker = obj()
198+ let thisLock = obj()
197199
198200member this.RegisterForIdleTime () =
199- mgr<- this.GetService( typeof< SOleComponentManager>) :?> IOleComponentManager
200- if componentID= 0 u&& not ( isNull mgr) then
201- let crinfo = Array.zeroCreate< OLECRINFO>( 1 )
202- let mutable crinfo0 = crinfo.[ 0 ]
203- crinfo0.cbSize<- Marshal.SizeOf( typeof< OLECRINFO>) |> uint32
204- crinfo0.grfcrf<- uint32(_ OLECRF.olecrfNeedIdleTime||| _ OLECRF.olecrfNeedPeriodicIdleTime)
205- crinfo0.grfcadvf<- uint32(_ OLECADVF.olecadvfModal||| _ OLECADVF.olecadvfRedrawOff||| _ OLECADVF.olecadvfWarningsOff)
206- crinfo0.uIdleTimeInterval<- 1000 u
207- crinfo.[ 0 ] <- crinfo0
208- mgr.FRegisterComponent( this, crinfo, & componentID) |> ignore
209-
201+
202+ if not ( isNull mgr) && componentID= 0 uthen
203+ lock( thisLock) ( fun _ ->
204+ if componentID= 0 uthen
205+ let crinfo = Array.zeroCreate< OLECRINFO>( 1 )
206+ let mutable crinfo0 = crinfo.[ 0 ]
207+ crinfo0.cbSize<- Marshal.SizeOf( typeof< OLECRINFO>) |> uint32
208+ crinfo0.grfcrf<- uint32(_ OLECRF.olecrfNeedIdleTime||| _ OLECRF.olecrfNeedPeriodicIdleTime)
209+ crinfo0.grfcadvf<- uint32(_ OLECADVF.olecadvfModal||| _ OLECADVF.olecadvfRedrawOff||| _ OLECADVF.olecadvfWarningsOff)
210+ crinfo0.uIdleTimeInterval<- 1000 u
211+ crinfo.[ 0 ] <- crinfo0
212+
213+ mgr.FRegisterComponent( this, crinfo, & componentID) |> ignore
214+ )
215+
210216/// This method loads a localized string based on the specified resource.
211217
212218/// <param name="resourceName">Resource to load</param>
@@ -358,11 +364,12 @@ namespace rec Microsoft.VisualStudio.FSharp.ProjectSystem
358364 VSConstants.S_ OK
359365
360366override this.Dispose ( disposing ) =
361- try
362- lock( locker) ( fun _ ->
363- if componentID<> 0 u&& not ( isNull mgr) then
364- mgr.FRevokeComponent( componentID) |> ignore
365- componentID<- 0 u)
367+ try
368+ if not ( isNull mgr) && componentID<> 0 uthen
369+ lock( thisLock) ( fun _ ->
370+ if componentID<> 0 uthen
371+ mgr.FRevokeComponent( componentID) |> ignore
372+ componentID<- 0 u)
366373finally
367374base .Dispose( disposing)
368375
@@ -379,7 +386,7 @@ namespace rec Microsoft.VisualStudio.FSharp.ProjectSystem
379386override this.FDoIdle ( grfidlef : uint32 ) =
380387// see e.g "C:\Program Files\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Common\IDL\olecm.idl" for details
381388//Trace.Print("CurrentDirectoryDebug", (fun () -> sprintf "curdir='%s'\n" (System.IO.Directory.GetCurrentDirectory()))) // can be useful for watching how GetCurrentDirectory changes
382- let periodic = ( grfidlef&&& ( uint32_ OLEIDLEF.oleidlefPeriodic)) <> 0 u
389+ let periodic = ( grfidlef&&& ( uint32_ OLEIDLEF.oleidlefPeriodic)) <> 0 u
383390if periodic&& not ( isNull mgr) && mgr.FContinueIdle() <> 0 then
384391 TaskReporterIdleRegistration.DoIdle( mgr)
385392else