private void InitializeApartmentDetails ()
{
// Only synchronization_context if thread is STA.
if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
return;
synchronization_context = SynchronizationContext.Current;
// Check whether the current context is a plain SynchronizationContext object
// and handle this as if no context was set at all.
if (synchronization_context != null &&
synchronization_context.GetType () == typeof(SynchronizationContext))
synchronization_context = null;
}