1

I am having this weird behavior:

Yesterday I was working on a WPF application on Visual Studio 2015 and I wanted to write some values to a console prompt while debugging so I included a console with my form.

Today, when I started visual studio, even without Starting the program, a console window pops up. This is weird. When traced it, it turned to be coming from loading the designer of visual studio:

Anyone has any idea why is that happening and how to fix it?

enter image description here

When I Disable Running Project Code I get this form where my ImageConrol looks like is kind of disabled, but the console never pops again:

enter image description here

Community
  • 1
  • 1
Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104
  • The WPF editor runs parts of your application to provide a live preview. It's usually useful, but it can be annoying in some situations, such as the one you're in. – Theodoros Chatzigiannakis Sep 14 '16 at 11:58
  • @TheodorosChatzigiannakis Also as (in other applications) the ImageControl shows the current image, live, so it keeps a hold of the image physical file and I can't rename, edit, delete, move the file.. etc because _it is being used by another program_. – Khalil Khalaf Sep 14 '16 at 12:00
  • Have you installed any 3rd party controls? – Rohit Sep 14 '16 at 12:01
  • @Rohit Well I have DevExpress stuff, and also ReSharper installed. I use these packages with several applications yet this behavior does not happen with the other applications – Khalil Khalaf Sep 14 '16 at 12:03
  • XDesProc.exe is a design rendering process which is spawned by Visual studio in the background – Rohit Sep 14 '16 at 12:07

1 Answers1

2

To display your control, WPF designer actually runs your code (not all of it, but still). So designer might execute your AllocConsole call, which leads to behavior you observe. To avoid this, do:

if (!DesignerProperties.GetIsInDesignMode(new DependencyObject())) {
    AllocConsole();
    Console.WriteLine("test");
}
Evk
  • 98,527
  • 8
  • 141
  • 191
  • 1
    It happens because designer executes your AllocConsole method (I actually was able to reproduce this). Designer does not execute all code, so maybe before you used this console in a part which did not get executed). Don't forget to rebuild project when you apply this fix (or comment AllocConsole out). – Evk Sep 14 '16 at 12:07
  • You can see on your screenshot that console you opened belongs to XDesProc.exe process. This is WPF designer process. When you closed console belonging to this process - it tears down whole process, so eventually terminates WPF designer (you can also see this on your screenshot). Why closing that console terminates process you can read here: http://stackoverflow.com/a/11960299/5311735. – Evk Sep 14 '16 at 12:20
  • Yup, makes complete sense now so thanks for the link :) – Khalil Khalaf Sep 14 '16 at 12:23