public void Launch(Id anArgument)
{
try
{
if (this.actionWithState != null)
{
var val = anArgument.SafeCastTo<NSValue>();
if (val != null)
{
GCHandle stateHandle = GCHandle.FromIntPtr(val.PointerValue);
Object state = stateHandle.Target;
stateHandle.Free();
this.actionWithState(state);
}
else
{
this.actionWithState(null);
}
}
else if (this.actionWithId != null)
{
this.actionWithId(anArgument);
}
else if (this.action != null)
{
this.action();
}
}
catch (Exception ex)
{
// If this delegate is invoked on a separate thread, the developer should have
// wrapped the body in a try / catch. If they didn't, at least log the
// exception to help them troubleshoot. Otherwise, the thread will just die
// and they may not notice an issue.
Logger.Debug("ObjectiveCRuntime", ex.ToString());
throw;
}
finally
{
this.Autorelease();
}
}
}