blog@mcZen

Software, life, and leisure

IE8 hangs while connecting to ip address

Currently rated 2.0 by 1 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

July 6, 2009 5:37 PM

mike

Ever since I started using IE 8, I have been having problems.  Very frustrating problems.  So frustrating, that the firefox icon is now right next to the IE icon.  (don't get me wrong, I like firefox.)

The Problem:

Internet Explorer was hanging, freezing, pausing, locking up.  It would not return a page 50% of the time, guaranteed.  So 25% of that time, I was getting "Connecting to ..." with an IP address.  I read blog post after blog post, re-registered dlls, disabled all add-ons and the problem was still happening.  I started the debugger in visual studio to see what DLLs were running... nothing out of the ordinary - no third party dlls currently running.  No processor spikes.  I was getting absolutely no where.  I was just about at the point of uninstalling IE8, but there had to be a solution.

The Answer:

It turns out that the problem was AVG and the link scanner.  Disabling the add-on is not enough.  You must run the installer again and remove the component.  There are probably lots of blog posts out there with information about the problem, but since I couldn't find it, here it is again.

By the way, I probably installed IE8 and the AVG 8.? on the same day, so who would have thought it was AVG?  well, I can't say it is AVG, but rather internet explorer doing something when it shouldn't because the add-on is disabled...

Generic Extension Methods

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

May 1, 2009 6:17 PM

mike

Generics 

Generics within C# give us the ability to create classes that provide functionality in a generic way.  This means we can take a class that has some underlying type and implement it so that all types can be used by the container class.  System.Collections.Generics provides some great examples of generics with their List and Dictionary implementations.

example:
System.Collections.Generics.List<string> types = new System.Collections.Generics.List<string>();
AND
System.Collections.Generics.List<Rect> types = new System.Collections.Generics.List<Rect>();

The implementation of List is standard but the template argument can be any available type.  We can also have generic functions, where the function defines a template and uses the generic type as either arguments or in the function.

Extension Methods 

Extension methods provide nice flexibility to extend existing class within .NET.  They allow us to add functions to classes that we can call on the object like it is an actual method on the class itself. 

example:
public static partial class Tools
{
   public static string ToBase64(this string s)
   {
      return System.Convert.ToBase64String( System.Text.Encoding.Unicode.GetBytes(s) );
   }
}

And we can call this function like it is part of the string class. 

string s = "base64";
string b64 = s.ToBase64();

The key parts to creating extension methods are they need to be in a static class and the first parameter has the "this" keyword which will apply the method to the given class.

Generic Extension Methods 

So now onto the topic: Generic Extension Methods.  What this means is creating an extension method from a generic function template.  So you now are probably asking "WHY?" or "When would I use this?"  Both are great questions, so I've got a great example.

I tend to be pattern oriented.  I use patterns constantly throughout my code.  One pattern is setting a property value and notifying listeners that the property has changed.  Instead of writing the same code over and over which checks the equality, then calls the handler if the value did-in-fact change.  Using a generic extension method is perfect for this use case. 

My code:
public static partial class Extensions
{
   public static bool SetAndNotify<T>(this T newValue, ref T oldValue, object sender, string propertyName, System.ComponentModel.PropertyChangedEventHandler handler)
   {
      if (newValue==null && oldValue==null) return false;
      if (newValue.Equals(oldValue)) return false;
      oldValue = newValue;
      if (handler!=null)
         handler(sender, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
      return true;
   }
}

And to use it:
...
   public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
   private SomeType _MyProperty = null;
   public SomeType MyProperty
   {
      get { return _MyProperty; }
      set { value.SetAndNotify<SomeType>(ref _MyProperty, this, "MyProperty", PropertyChanged); }
   }
...

As you can see, anytime I need to notify when a property is changed, I can just use the above code over and over.  It's important to note that with this code, I pass the reference of the member variable.  This allows me to change the value.  And there you have it, a Generic Extension Method.  

It should also be noted... This code is only checking for nulls.  we should probably also check for default(T) in the instance where T is a struct, but I don't have time to try it...

UPDATE: You can also call the SetAndNotify without explicitly declaring the template, but I like to be explicit.
[Insert explicitive here]

Powered by BlogEngine.NET 1.4.5.7