Skip to content

Commit

Permalink
Dispose FSharpProjectPackage properly (#2058)
Browse files Browse the repository at this point in the history
* Dispose FSharpProjectPackage properly

* Ensure that revoking component is thread-safe
  • Loading branch information
dungpa authored and KevinRansom committed Dec 20, 2016
1 parent 0e6614e commit 07c3f37
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions vsintegration/src/FSharp.ProjectSystem.FSharp/Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ namespace rec Microsoft.VisualStudio.FSharp.ProjectSystem
let mutable mgr : IOleComponentManager = null
let mutable componentID = 0u

let locker = obj()

member this.RegisterForIdleTime() =
mgr <- this.GetService(typeof<SOleComponentManager>) :?> IOleComponentManager
if componentID = 0u && not (isNull mgr) then
Expand All @@ -203,10 +205,7 @@ namespace rec Microsoft.VisualStudio.FSharp.ProjectSystem
crinfo0.grfcadvf <- uint32 (_OLECADVF.olecadvfModal ||| _OLECADVF.olecadvfRedrawOff ||| _OLECADVF.olecadvfWarningsOff)
crinfo0.uIdleTimeInterval <- 1000u
crinfo.[0] <- crinfo0
let componentID_out = ref componentID
let _hr = mgr.FRegisterComponent(this, crinfo, componentID_out)
componentID <- componentID_out.Value
()
mgr.FRegisterComponent(this, crinfo, &componentID) |> ignore

/// This method loads a localized string based on the specified resource.
Expand Down Expand Up @@ -355,6 +354,15 @@ namespace rec Microsoft.VisualStudio.FSharp.ProjectSystem
pIdIco <- 400u
VSConstants.S_OK

override this.Dispose(disposing) =
try
lock (locker) (fun _ ->
if componentID <> 0u && not (isNull mgr) then
mgr.FRevokeComponent(componentID) |> ignore
componentID <- 0u)
finally
base.Dispose(disposing)

interface Microsoft.VisualStudio.FSharp.Interactive.ITestVFSI with
member this.SendTextInteraction(s:string) =
GetToolWindowAsITestVFSI().SendTextInteraction(s)
Expand Down

0 comments on commit 07c3f37

Please sign in to comment.