It’s a question I have seen a few times on the Microsoft forums: How do you get the default system proxy settings? Well, let me tell you the answer:
WebRequest.GetSystemWebProxy will return a proxy object with the default system proxy in it.
Using the DefaultWebProxy property on WebRequest you can get the proxy for the system unless it has been overridden in your app.config file. This is the best property to use so your app can be repointed to a different proxy. That property can also be set by your code to repoint your app
So that’s the simplest way to get hold of the proxy settings for Windows apps.
Ok, a new method on System.Enviroment in .NET 4.0 is the FailFast method. This a new nuclear option for ending your program should it have gone horribly, horribly wrong. There are 2 overloads, one takes a string, the other takes the string and an exception. When the application exits the string and exception details are written the event log and a dump is created for the application.
One thing to note is that NO catch blocks, finalizers or any other form of code will run in the application. This can be a good thing if your finalizers clean up stuff that in bad crashes you would rather was left behind. However, be careful, it means any Dispose methods or Finalizers that release shared or unmanaged resources will also not run.
Its nice they gave us the nuclear option, but we should also be careful how they are used.
Ok, so first ‘Better Know A Framework’. This one is for the new .NET 4.0 method HasFlag on System.Enum
I chose this one because a while back in my blog I posted an Enum helper that had a method like this. The method just replaces the:
bool isFlagSet = (value & flag == flag);
bool isFlagSet = value.HasFlag(flag);
Another helpful little thing is that the flag value you pass in can also be a combination of flag values. Its simple but helpful. However on my helper, I also put the SetFlag method. Maybe Microsoft are working that one up for .NET 5
So that’s it for the first of these, there is the new method, give it a whirl
Ok, so for those of you that listen to DotNetRocks then you will have heard Carls ‘Better Know a Framework’ bit. Well this is my version, posts in this category will be telling you about a little bit of the framework I have discovered or just one that I like. I’ll tell you what its for and how to use it. Like a little mini-guide.
Its open to requests too, so send ‘em if you got ‘em