Detecting that You're Running in a ClickOnce Application

In my last post,  I mentioned that application scoped isolated storage only works if you're running in a ClickOnce application.  That begs the question -- how do I tell if I'm currently running in the context of a ClickOnce application?

You can see if a ClickOnce application is running in the current AppDomain by checking the AppDomain.CurrentDomain.ActivationContext property.  If that value is non-null, then the domain is running a ClickOnce application.  The ActivationContext will also get you the name of that application.

What you choose to do with that information is up to you.  In general, modifying your behavior depending on the context of the application leads to difficult to test and debug programs.  However, there may be situations (such as choosing an isolated storage scope), where having this information is necessary and useful.