Support managed object context detection with arrays

This detects if the object is an array and looks at the object inside it to determine if there is a managed object context available. Otherwise it defaults to the main thread leading to deadlocks in some situations.