I have often seen code examples of delegate invocation being done as follows:
`
public delegate void DelegateThreadActivity<T, U> (T sender, U e);
public event DelegateThreadActivity<Thread, System.EventArgs> OnStart = null;
public event DelegateThreadActivity<Thread, System.EventArgs> OnStop = null;
// Helper method for invocation.
public void RaiseOnStart ()
{
DelegateThreadActivity<Thread, System.EventArgs> instance = null;
try
{
instance = this.OnStart;
// OR
instance = (DelegateThreadActivity) (object) this.OnStart;
if (instance != null)
{
instance(this, System.EventArgs.Empty);
}
}
catch
{
}
}
`
Why use the [instance]
object at all? At first I thought it was corporate convention but have seen seasoned developers do this as well. What is the benefit?