简体   繁体   中英

Code is running when debugger stop?

I'm connecting to an ssh server when my application starts. Therefor I'm using the SSH.net Library. When I start Visual Studio and open the main wpf view Visual Studio is starting this connection in background even when my program is not running. So when I start my program with the debugger I get an "Only one usage of each socket address" exception. I have Visual Studio 2010 + Wpf + Caliburn Micro running.

Why is Visual Studio doing that?

Regards Markus

Sounds like the Visual Studio Designer is opening the connection when you open the window. Probably because the function that opens the connection is in the constructor, which is called by the designer to show the window...

Add the following code in the function that opens the SSH connection to prevent the connection from opening if you're in the designer:

bool isInDesignMode = System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject());
if (isInDesignMode)
     return;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM