Example #1
0
        /// <summary>
        /// Compares the SynchronizationContext of the current thread and of this messenger instance.
        /// </summary>
        private bool CompareSynchronizationContexts()
        {
#if DESKTOP
            if (SynchronizationContext.Current == m_syncContext)
            {
                return(true);
            }

            System.Windows.Threading.DispatcherSynchronizationContext left =
                SynchronizationContext.Current as System.Windows.Threading.DispatcherSynchronizationContext;
            System.Windows.Threading.DispatcherSynchronizationContext right =
                m_syncContext as System.Windows.Threading.DispatcherSynchronizationContext;
            if (left == null)
            {
                return(false);
            }
            if (right == null)
            {
                return(false);
            }

            var leftDispatcher = CommonTools.ReadPrivateMember <System.Windows.Threading.Dispatcher, System.Windows.Threading.DispatcherSynchronizationContext>(
                left, "_dispatcher");
            var rightDispatcher = CommonTools.ReadPrivateMember <System.Windows.Threading.Dispatcher, System.Windows.Threading.DispatcherSynchronizationContext>(
                right, "_dispatcher");

            return(leftDispatcher == rightDispatcher);
#else
            return(SynchronizationContext.Current == m_syncContext);
#endif
        }
Example #2
0
        public static System.Windows.Threading.DispatcherSynchronizationContext CreateDispatchContext()
        {
            var syncContext = new System.Windows.Threading.DispatcherSynchronizationContext(
                System.Windows.Threading.Dispatcher.CurrentDispatcher);

            System.Threading.SynchronizationContext.SetSynchronizationContext(syncContext);
            return(syncContext);
        }
Example #3
0
        internal Application(IntPtr raw, bool dropref)
        {
            NativeHandle = raw;
            if (dropref)
            {
                NativeMethods.event_object_unref(raw);
            }

            strongRefs = new Dictionary <IntPtr, object> ();

            NativeDependencyObjectHelper.SetManagedPeerCallbacks(this);

            get_implicit_styles    = new GetImplicitStylesCallback(get_implicit_styles_cb_safe);
            convert_setter_values  = new ConvertSetterValuesCallback(convert_setter_values_cb_safe);
            convert_keyframe_value = new ConvertKeyframeValueCallback(convert_keyframe_value_cb_safe);
            get_resource           = new GetResourceCallback(get_resource_cb_safe);

            NativeMethods.application_register_callbacks(NativeHandle, get_implicit_styles, convert_setter_values, get_resource, convert_keyframe_value);

            if (Current == null)
            {
                Current = this;

                SynchronizationContext context = new System.Windows.Threading.DispatcherSynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(context);
            }
            else
            {
                root_visual = Current.root_visual;
            }

            lifetime_objects = new ApplicationLifetimeObjectsCollection();

            // once installed the default quota for isolated storage is augmented to 25MB (instead of 1MB)
            // note: this applies only to the browser (not desktop) assemblies (it won't compile otherwise)
#if !NET_3_0
            if (IsRunningOutOfBrowser)
            {
                long OutOfBrowserQuota = 25 * IsolatedStorage.DefaultQuota;
                if (IsolatedStorage.Quota < OutOfBrowserQuota)
                {
                    IsolatedStorage.Quota = OutOfBrowserQuota;
                }
            }
#endif
            var handler = UIANewApplication;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
Example #4
0
		internal Application (IntPtr raw, bool dropref)
		{
			NativeHandle = raw;
			if (dropref)
				NativeMethods.event_object_unref (raw);

			strongRefs = new Dictionary<IntPtr,object> ();

			NativeDependencyObjectHelper.SetManagedPeerCallbacks (this);

			get_default_style = new GetDefaultStyleCallback (get_default_style_cb_safe);
			convert_setter_values = new ConvertSetterValuesCallback (convert_setter_values_cb_safe);
			convert_keyframe_value = new ConvertKeyframeValueCallback (convert_keyframe_value_cb_safe);
			get_resource = new GetResourceCallback (get_resource_cb_safe);

			NativeMethods.application_register_callbacks (NativeHandle, get_default_style, convert_setter_values, get_resource, convert_keyframe_value);

			if (Current == null) {
				Current = this;

				SynchronizationContext context = new System.Windows.Threading.DispatcherSynchronizationContext ();
				SynchronizationContext.SetSynchronizationContext (context);
			} else {
				root_visual = Current.root_visual;
			}

			lifetime_objects = new ApplicationLifetimeObjectsCollection ();

			// once installed the default quota for isolated storage is augmented to 25MB (instead of 1MB)
			// note: this applies only to the browser (not desktop) assemblies (it won't compile otherwise)
#if !NET_3_0
			if (IsRunningOutOfBrowser) {
				long OutOfBrowserQuota = 25 * IsolatedStorage.DefaultQuota;
				if (IsolatedStorage.Quota < OutOfBrowserQuota)
					IsolatedStorage.Quota = OutOfBrowserQuota;
			}
#endif
			var handler = UIANewApplication;
			if (handler != null)
				handler (this, EventArgs.Empty);
		}
Example #5
0
		internal Application (IntPtr raw, bool dropref)
		{
			NativeHandle = raw;
			if (dropref)
				NativeMethods.event_object_unref (raw);

			strongRefs = new Dictionary<IntPtr,INativeEventObjectWrapper> ();

			NativeDependencyObjectHelper.SetManagedPeerCallbacks (this);

			get_default_style = new GetDefaultStyleCallback (get_default_style_cb_safe);
			convert_setter_values = new ConvertSetterValuesCallback (convert_setter_values_cb_safe);
			convert_keyframe_value = new ConvertKeyframeValueCallback (convert_keyframe_value_cb_safe);
			get_resource = new GetResourceCallback (get_resource_cb_safe);

			NativeMethods.application_register_callbacks (NativeHandle, get_default_style, convert_setter_values, get_resource, convert_keyframe_value);

			if (Current == null) {
				Current = this;

				SynchronizationContext context = new System.Windows.Threading.DispatcherSynchronizationContext ();
				SynchronizationContext.SetSynchronizationContext (context);
			} else {
				root_visual = Current.root_visual;
			}

			lifetime_objects = new ApplicationLifetimeObjectsCollection ();

			var handler = UIANewApplication;
			if (handler != null)
				handler (this, EventArgs.Empty);
		}