/// <summary>
		/// Initializes a new instance of the <see cref="CreateOnUIThreadActivator"/> class.
		/// </summary>
		/// <param name="model">The model.</param>
		/// <param name="kernel">The kernel.</param>
		/// <param name="onCreation">Delegate called on construction.</param>
		/// <param name="onDestruction">Delegate called on destruction.</param>
		public CreateOnUIThreadActivator(ComponentModel model, IKernel kernel, ComponentInstanceDelegate onCreation,
		                                 ComponentInstanceDelegate onDestruction)
			: base(model, kernel, onCreation, onDestruction)
		{
			customActivator = CreateCustomActivator(model, kernel);
			performCreation = PerformCreation;
		}
Пример #2
0
        private static object CreateOnDispatcherUIThread(CreationContextDelegate performCreation, CreationContext context)
        {
            var application = Application.Current;

            if (application != null && application.CheckAccess() == false)
            {
                return(application.Dispatcher.Invoke((CreateOnUIThreadDelegate)CreateOnDispatcherUIThread, performCreation, context));
            }

            return(performCreation(context));
        }
		private object CreateOnWinformsUIThread(CreationContextDelegate performCreation, CreationContext context)
		{
			if (marshalingControl.InvokeRequired)
			{
				return marshalingControl.Invoke((CreateOnUIThreadDelegate)CreateOnWinformsUIThread, performCreation, context);
			}

			var component = performCreation(context);
			var control = (Control)GetUnproxiedInstance(component);
			if (control.Handle == IntPtr.Zero)
			{
				throw new InvalidOperationException("The WinForms control handle could not be obtained");
			}
			return component;
		}
        private object CreateOnWinformsUIThread(CreationContextDelegate performCreation, CreationContext context)
        {
            if (marshalingControl.InvokeRequired)
            {
                return(marshalingControl.Invoke((CreateOnUIThreadDelegate)CreateOnWinformsUIThread, performCreation, context));
            }

            var component = performCreation(context);
            var control   = (Control)GetUnproxiedInstance(component);

            if (control.Handle == IntPtr.Zero)
            {
                throw new InvalidOperationException("The WinForms control handle could not be obtained");
            }
            return(component);
        }
		private static object CreateOnDispatcherUIThread(CreationContextDelegate performCreation, CreationContext context)
		{
			var application = Application.Current;

			if (application != null && application.CheckAccess() == false)
			{
				return application.Dispatcher.Invoke((CreateOnUIThreadDelegate)CreateOnDispatcherUIThread, performCreation, context);
			}

			return performCreation(context);
		}