开发者

Checking if a WPF app is being run from within visual studio

I have a WPF app whic开发者_如何学Pythonh calls some WCF services which are in a separate project in the same solution. When this app is deployed these WCF services are hosted using a windows service running on the same machine (they need to be hosted outside of the main app).

I have some code which checks the status of the windows services on startup however I only want this to run when the app is deployed, not when I am running it from within Visual Studio - is this possible?


You may be able to use the DesignerProperties.IsInDesignMode property. But this just tells you if your code is running in the context of the Visual Studio designer (i.e. while designing XAML files).

You can use the Debugger.IsAttached property to see if a debugger is attached while your application is running.

Otherwise, you're best bet would be to wrap your checks in a #if-#endif and define a symbol in release builds to include your checks.


It's easy if you use ClickOnce:

if (ApplicationDeployment.IsNetworkDeployed)
{
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜