conhost.exe process duplication in Visual Studio | can't close conhost - visual-studio

I have a windows forms project and it several forms each one had a button to close the one form and open another by doing that code:
private void button3_Click(object sender, EventArgs e)
{
Menu MenuForm = new Menu();
MenuForm.Show(); // Shows main menu
this.Hide();
}
When I switched between forms it duplicated consoles on the background and i can't close it.
I tried debug=>stop debugging and manually killing process in task manager.

enter image description here
all consoles consume such memory in my pc, they seem to automatically run as i open VS

Related

xamarin application not quitting right

I noticed something strange with my Xamarin application.
First in Xamarin: Running the Application was fine until I click the upper right X to close the App. In Xamarin the button on the left is still a red square and I can "stop the current startup project".
Second: after packing up the application (7zip) and starting it out of the archive, after closing the app, 7zip told me to stop the application before it is able to close the archive.
Is there anything i'm missing here? Do i have to setup anything to shutdown the App properly?
there even is a OnDeleteEvent
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
{
Application.Quit();
a.RetVal = true;
}
but with a breakpoint there, it seems not to be used when clicking the X-Button.
Note: I'm using the GTK#2.0 Project template with Xamarin 6.2
i had to add the line
this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent);
into the sourcecode of my MainWindow. Somehow this line was missing.
It's working as intended now.

VS SDK: ToolWindowPane hides when debugging

I used the VS 2010 SDK to create and show a custom ToolWindowPane with a WPF control as content. I create a new instance and show it each time a Tool menu item is clicked (the ProvideToolWindow attribute has MultiInstances = true).
When the user attaches the debugger (e.g., hits F5 while in C# project) my ToolWindowPane suddenly hides. I'd like to make sure my tool window is always visible while open, no matter what context the user is in. Is there a way I can enforce that?
I've tried using the ProvideToolWindowVisibility attribute but that automatically shows a new instance of my tool window rather than keeping a remaining one open.
For VS 2010 SDK Microsoft added a new flag __VSCREATETOOLWIN2.CTW_fDocumentLikeTool
You can use this way:
public override void OnToolWindowCreated()
{
IVsWindowFrame windowFrame = Frame as IVsWindowFrame;
object varFlags;
windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_CreateToolWinFlags, out varFlags);
int flags = (int)varFlags | (int)__VSCREATETOOLWIN2.CTW_fDocumentLikeTool;
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_CreateToolWinFlags, flags);
}
This way Tool Window persist open at "Document Well" when you go Debugging
However I have to say this give us some problems when debugging projects, avoiding us to open code files while debugging, like if Visual Studio document management was 'block', there are not so much information for this new flag...
So we preferred to hook to EnvDTE.DebuggerEvents and show the ToolWindow if hide when a debugging session start...
(our ToolWindow has MultiInstances = false)
Implement QueryShowTool
public:
int QueryShowTool(Guid % rguidPersistenceSlot, System::UInt32 dwId, [Runtime::InteropServices::Out] int % pfShowTool);
Enables the VSPackage to control whether to show or hide the tool
window. The shell calls this method when the user switches views or
contexts, for example Design, Debugging, Full Screen.
See https://learn.microsoft.com/en-us/visualstudio/extensibility/opening-a-dynamic-tool-window?view=vs-2017

WPF Application crashes on WIndows 7 when command executable.Start() is run

I've got a tiny Portal I´m writing, and this portal is supposed to launch installers on button click. I´m developing on VS2010 on a WinXP SP3 station, and on this machine, even fter compilation and publishing, everything works as expected. However, when i run the compiled application in Windows 7, it crashes...The application work, it just crashes when i click a button for program installation.
The programming looks like this:
private void button_access_Click(object sender, RoutedEventArgs e)
{
Process executable = new Process();
string executablePath = "D:\\Visual Studio 2010\\SAFE_Portal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
executable.StartInfo.FileName = executablePath;
executable.Start();
}
It specifically crashes on thr button_access_Click procedure...
Any ideas as to why this could be? I`ve tried looking around here in Stackoverflow, and in other forums, but to no avail...
Any help or direction is ganz welcome!
Try this:
try
{
Process executable = new Process();
string executablePath = "D:\\Visual Studio 2010\\SAFE_Portal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
executable.StartInfo.FileName = executablePath;
executable.Start();
}
catch (Exception msg)
{
MessageBox.Show(msg.Message);
}
What message are you getting?
Are you sure you want to use fixed paths in your application? If so you should at least check if the file you try to start exists beforehand. Otherwise an exception will be thrown which could be the problem here.
if (File.Exists(executablePath))
{
...
}

Test App failing on Back Button... Windows Phone 7

Ok this question stems from this question:
wp7: App failing! Can not figure out where?
I thought it was corrected but it is still failing. I ripped out all of the app.xaml.cs code and it still crashing when the search button is clicked and the back button is immediately pressed.
So... I decided to see if I could replicate the issue with a new test app. Basically I have create a basic pivot application with the default Main View Model. None of my code exists...
I press the search button and then immediately press the back button and low and behold... The SAME THING HAPPENS.... It crashes the application, the emulator shows a blank screen and the debugger stops!
So... That leads me to believe that I've found a bug in the emulator (I find this very hard to believe)... OR, my Studio environment maybe is corrupted (I'm hoping it is not).
I'm not sure where to go on this one. I don't know what the error is, and it is preventing my apps from being accepted on the market place.
Does anyone have any ideas?
I made a screen capture of what I'm seeing:
Notice that the 1st 3 search/back combos work as the boxes in the search screen are allowed to display. However, the last 2 search/back combos don't work as you will see that the boxes aren't allowed to display...
http://www.youtube.com/watch?v=XVht3OtBGaI
The error report I'm getting from Microsoft:
Comments: The application reactivate after deactivation and terminates unexpectedly.
Steps to reproduce:
1) Launch the application.
2) Select a vehicle.
3) Press the device's "Start" button.
4) Select the device's "Back" button.
5) Observe the application terminates unexpectedly and does not reactive the application.
This error is reproducible 8 out of 10 times.
The other error report from a different application:
Comments: The application terminates rather than resuming when the user attempts to return from a Search.
Steps to reproduce:
1. Launch the application
2. Select the Add + button
3. Press the Search button
4. Press the Back button
5. Observe the application terminates after a few seconds.
I noticed that:
When the following happens in the debugger:
The thread '<No Name>' (0xd1b0092) has exited with code 0 (0x0).
The thread '<No Name>' (0xd6900ba) has exited with code 0 (0x0).
That the project DOES NOT FAIL as described (100% of the time). However, if I click the back button before this, then the application fails (100% of the time).
Update #1: App.xaml.cs
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
// Ensure that application state is restored appropriately
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
// Ensure that required application state is persisted here.
}
OK, after hours of banging my head against my desk I have found that the emulator on some machines are having the same issue I am seeing.
So... The 1st thing I did was to wrap all my functions in Try/Catch blocks... Even the smallest functions and the ones that can't error. Then I side loaded the application to see if I can get it to crash. When I felt I sufficiently tested it on my phone I re-submitted the app. In the testing notes section I asked for them to test it on a device rather than an emulator. I never heard if they did this or not, but they passed my app, so I'm guessing that they did.
Thanks to #Praetorian and #Matt Lacey and #willmel and anyone else that took a look at this problem for me. I appreciate it!
I also noticed that If you create an new wp7 application this also happend.
Create a new application. Start it.
When it has started press the Start button and immidiately click the back button. It now says Resuming.. but nothing happens.
When you try to restart the app you only get to the splashscreen.
But I found out that if you build the app using Build=Release and dont debug the app (run it on a device) this does not occur..
Can you check if this is the case for you as well.. If so them im also in trouble

How to attach a debugger dynamically to a specific process

I am building an internal development tool to manage different processes commonly used in our development environment. The tool shows the list of the monitored processes, indicating their running state and allows to start or stop each process.
I'd like to add the functionality of attaching a debugger to a monitored process from my tool instead of going in Debug -> Attach to process in Visual Studio and finding the process.
My goal is to have something like Debugger.Launch() that would show a list of the available Visual Studio. I can't use Debugger.Launch(), because it launches the debugger on the process that makes the call. I would need something like Debugger.Launch(processId).
How do I achieve this functionality?
A solution could be to implement a command in each monitored process to call Debugger.Launch() when the command is received from the monitoring tool, but I would prefer something that does not require to modify the code of the monitored processes.
Side question:
When using Debugger.Launch(), instances of Visual Studio that already have a debugger attached are not listed. Visual Studio is not limited to one attached debugger, you can attach on multiple process when using Debug → Attach to process.
How do I bypass this limitation when using Debugger.Launch() or an alternative?
A coworker ended up with a solution using DTE, and I posted the code on PasteBin.
The methods of interest are AttachVisualStudioToProcess and TryGetVsInstance
Source Code
public static void AttachVisualStudioToProcess(Process visualStudioProcess, Process applicationProcess)
{
_DTE visualStudioInstance;
if (TryGetVsInstance(visualStudioProcess.Id, out visualStudioInstance))
{
//Find the process you want the Visual Studio instance to attach to...
DTEProcess processToAttachTo = visualStudioInstance.Debugger.LocalProcesses.Cast<DTEProcess>().FirstOrDefault(process => process.ProcessID == applicationProcess.Id);
// Attach to the process.
if (processToAttachTo != null)
{
processToAttachTo.Attach();
ShowWindow((int)visualStudioProcess.MainWindowHandle, 3);
SetForegroundWindow(visualStudioProcess.MainWindowHandle);
}
else
{
throw new InvalidOperationException("Visual Studio process cannot find specified application '" + applicationProcess.Id + "'");
}
}
}
private static bool TryGetVsInstance(int processId, out _DTE instance)
{
IntPtr numFetched = IntPtr.Zero;
IRunningObjectTable runningObjectTable;
IEnumMoniker monikerEnumerator;
IMoniker[] monikers = new IMoniker[1];
GetRunningObjectTable(0, out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
{
IBindCtx ctx;
CreateBindCtx(0, out ctx);
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
if (runningObjectVal is _DTE && runningObjectName.StartsWith("!VisualStudio"))
{
int currentProcessId = int.Parse(runningObjectName.Split(':')[1]);
if (currentProcessId == processId)
{
instance = (_DTE)runningObjectVal;
return true;
}
}
}
instance = null;
return false;
}
WinDbg does the chain debugging for native code by default. If you want to launch another instance of Visual Studio, check Launch the Debugger Automatically on MSDN:
To automate the existing debugger, use Marshal.GetActiveObject to get the current EnvDTE.Debugger then let it attach to the process you just created.
Sometimes, you may need to debug the startup code for an application that is launched by another process. Examples include services and custom setup actions. In these scenarios, you can have the debugger launch and automatically attach when your application starts.
To setup an application to launch the debugger automatically
Start the Registry Editor (regedit).
In the Registry Editor, open the HKEY_LOCAL_MACHINE folder.
Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\currentversion\image file execution options.
In the Image File Execution Options folder, locate the name of the application you want to debug, such as myapp.exe. If you cannot find the application you want to debug:
a. Right-click the Image File Execution Options folder, and on the shortcut menu, click New Key.
b. Right-click the new key, and on the shortcut menu, click Rename.
c. Edit the key name to the name of your application; myapp.exe, in this example.
Right-click the myapp.exe folder, and on the shortcut menu, click New String Value.
Right-click the new string value, and on the shortcut menu, click Rename.
Change the name to debugger.
Right-click the new string value, and on the shortcut menu, click Modify.
The Edit String dialog box appears.
In the Value data box, type vsjitdebugger.exe.
Click OK.
From the Registry menu, click Exit.
The directory containing vsjitdebugger.exe must be in your system path. To add it to the system path, follow these steps:
a. Open the Control Panel in Classic view, and double-click System.
b. Click Advanced System Settings.
c. In System Properties, click the Advanced tab.
d. On the Advanced tab, click Environment Variables.
e. In the Environment Variables dialog box, under System variables, select Path, then click the Edit button.
f. In the Edit System Variable dialog box, add the directory to the Variable value box. Use a semicolon to separate it from other entries in the list.
g. Click OK to close the Edit System Variable dialog box.
h. Click OK to close the Environment Variables dialog box.
i. Click OK to close the System Properties dialog box.
Now, use any method to start your application. Visual Studio will start and load the application.
Here is some information about how you can programmatically attach the debugger to multiple processes:
Attach to locally running processes
Attach to remotely running processes

Resources