For several months, I’ve been troubled by an odd phenomenon when using Visual Studio.

Its first occurrence was several months ago, when I was using Visual Studio to work on a foobar2000 component. I had foobar2000 running in the background, intermittently playing music while I was testing my component. Suddenly, when looking at the taskbar, I realised foobar2000 was no longer running. ‘Weird’, I thought, wondering if I’d somehow accidentally closed it. I started foobar2000 again, and it started playing music. I was suspicious – it wasn’t playing what I thought it had been most recently – but there was else untoward that I could see.

Similar events would occur in the months ahead. I’d be happily coding away in Visual Studio when foobar2000 would suddenly disappear from the taskbar. It felt like foobar2000 was crashing, but there would be no crash log generated by foobar2000. Neither would there be anything relevant logged in the Windows Event Viewer. What was going on? I feared that it could be an odd bug in one of my foobar2000 components. So, I spent a fair bit of time deliberately using foobar2000 without Visual Studio running. The problem didn’t occur once.

I thought I’d found a pattern by around the fourth time it’d happened. Each time it had happened, I’d been pressing the Ctrl key as part of a keyboard shortcut, and that particular time I was using Ctrl-C and Ctrl-V to copy and paste some code. I wondered: was I inadvertently pressing the key combination for a malfunctioning foobar2000 global shortcut? I thought this was plausible, because I used to have Win-Z assigned as a global shortcut to close foobar2000. Alas, it couldn’t be that, as the shortcut was no longer assigned. Perhaps there was an obscure clipboard bug in foobar2000 when copying text. Nope – I tried all the clipboard operations I could think of but was unable to reproduce the problem.

The next time the problem occurred, some things would be similar – Visual Studio would be running, and I would be pressing Ctrl again. But this time, I wasn’t pressing Ctrl in the Visual Studio window, but I was instead pressing Ctrl-C and Ctrl-V in Windows Explorer to copy and paste a foobar2000 component. It was a slight deviation to the pattern I thought I’d found, and I wasn’t sure what to make of it.

Every attempt to deliberately reproduce the problem so far had failed. I thought my best bet would be to try and reproduce the problem while foobar2000 was running in a debugger, in the hope something interesting would happen. I set about deliberately running foobar2000 in a debugger while I was using Visual Studio. Alas, the problem didn’t reoccur, and running foobar2000 in a debugger this made my typical workflow difficult, as I’d usually be frequently stopping and starting foobar2000 while working on a component and would need to make sure foobar2000 was running in a debugger each time I restarted it.

At this point, I thought Process Monitor may be worth a try. Perhaps it would be able to tell me the exit status of the foobar2000 process next time it spontaneously closes. I started keeping Process Monitor running while using Visual Studio. For a while, the problem didn’t reoccur. But eventually, I struck gold: I was pressing Ctrl-Z (undo) and Ctrl-Shift-Z (redo) in a loop, and, on perhaps the ninth repetition, the problem reoccurred and was captured in Process Monitor.

I set about looking through the log, and what I saw wasn’t exactly what I was expecting:

The first solid piece of evidence didn’t get me very far

I hoped and thought the exit status would to be an exception or error code of some kind. But what I had was a mysterious -1. It increasingly felt like something was deliberately terminating foobar2000, but there was no sign of what, or why.

The most recent occurrence of the problem, some time later, would add to the confusion. Again, I was writing code in Visual Studio, and again a program disappeared from my taskbar. But this time I wasn’t pressing Ctrl when it happened – I was just typing code (the start of a class declaration, if I recall correctly). That wasn’t the only thing that was different this time: it was Firefox that vanished from my taskbar, rather than foobar2000.

Unfortunately, that takes us up to the present time and the mystery remains unsolved (a somewhat disappointing end to this post). Nonetheless, I can still speculate about what the cause of the problem. The main explanations I can think of are:

  • it’s something that Visual Studio is inadvertently doing
  • it’s something a Visual Studio extension is inadvertently doing
  • it’s something Windows is doing, that happens to trigger when Visual Studio is running because it’s a resource hog

Alas, those are just guesses, and given how infrequently the problem occurs, I won’t be finding out the true cause anytime soon.