Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbevans/45dd66f147277a2ea3dd to your computer and use it in GitHub Desktop.
Save nbevans/45dd66f147277a2ea3dd to your computer and use it in GitHub Desktop.
Temporary productivity workaround for Xamarin bug #31423
open System.Diagnostics
open System.Text.RegularExpressions
// Pre-req: FSharp runtime
// Usage: run from command line using "fsi.exe kill-locked-handles.fsx" no quotes
// Hints & tips as follows:
// Prepare the script by editing line 11 with a search string that will be used by handle.exe
// Ensure handle.exe (from SysInternals) is in your PATH, or edit this script to use an absolute path, or ensure handle.exe is in same path as this script.
// Edit into your build script or pre-build event on your project so this script is run each time.
let psi = new ProcessStartInfo("handle.exe", @"-p devenv.exe singapore.mobile.android\bin\debug\", RedirectStandardOutput = true, UseShellExecute = false)
let proc = Process.Start(psi)
proc.WaitForExit(5000) |> ignore
let output = proc.StandardOutput.ReadToEnd()
let regex = new Regex(@"devenv.exe pid: (?<ProcessId>\d+) type: File (?<FileHandle>[0-9a-f]+): ", RegexOptions.ExplicitCapture ||| RegexOptions.IgnoreCase)
for m in regex.Matches(output) |> Seq.cast<Match> do
let processId, fileHandle = m.Groups.["ProcessId"].Value, m.Groups.["FileHandle"].Value
let psi = new ProcessStartInfo("handle.exe", sprintf "-p %s -c %s -y" processId fileHandle, UseShellExecute = false)
Process.Start(psi).WaitForExit(5000) |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment