public override void ButtonCallback(object sender, EventArgs e) { ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var menuCommand = sender as OleMenuCommand; if (menuCommand == null) { return; } if (!m_downloading) { try { m_downloading = true; menuCommand.Visible = false; // We're just going right back to doing something on the UI thread, so just resume back on the UI thread. if (!await CheckForInternetConnectionAsync().ConfigureAwait(true)) { m_downloading = false; menuCommand.Visible = true; return; } m_monoFile.ResetToDefaultDirectory(); bool downloadNew = !m_monoFile.CheckFileValid(); if (downloadNew) { Output.ProgressBarLabel = "Downloading Mono"; await m_monoFile.DownloadMonoAsync(Output).ConfigureAwait(false); //Verify Download bool verified = m_monoFile.CheckFileValid(); if (verified) { // Show a Message Box to prove we were here await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsUIShell uiShell = Package.PublicGetService <IVsUIShell, SVsUIShell>(); Guid clsid = Guid.Empty; int result = await ShowMessageAsync("Mono Successfully Downloaded. Would you like to install it to the RoboRIO?", string.Empty).ConfigureAwait(false); if (result == 6) { //Install Mono. await m_installButton.DeployMonoAsync(m_installButton.GetMenuCommand()).ConfigureAwait(false); } } else { // Show a Message Box to prove we were here await ShowMessageAsync("Mono Download Failed. Please Try Again", string.Empty).ConfigureAwait(false); } } else { // Show a Message Box to prove we were here IVsUIShell uiShell = Package.PublicGetService <IVsUIShell, SVsUIShell>(); await ShowMessageAsync("Mono Already Downloaded", string.Empty).ConfigureAwait(false); } } catch (Exception ex) { await Output.WriteLineAsync(ex.ToString()).ConfigureAwait(false); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); m_downloading = false; menuCommand.Visible = true; } await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); m_downloading = false; menuCommand.Visible = true; } }); }