Esempio n. 1
0
 /// <summary>
 /// Executes an operation on the current thread (assuming the current thread is a background thread),
 /// but marshalls any exceptions back to the UI thread for you.
 /// </summary>
 /// <param name="backgroundThreadCallback">A code block to execute on the background thread.</param>
 public void ExecuteOnCurrentThreadWithExceptionsOnUIThread(Action backgroundThreadCallback)
 {
     try
     {
         backgroundThreadCallback();
     }
     catch (Exception ex)
     {
         TraceSources.MagellanSource.TraceError("Exeption thrown on worker thread: " + ex);
         var rethrower = new Rethrower("An unexpected error occurred when executing a background operation.", ex);
         Dispatch(rethrower.Rethrow);
     }
 }
Esempio n. 2
0
        public void TestInit()
        {
            appDomain = AppDomain.CreateDomain("Test App Domain", null, null);

            // load all required assemblies:
            var a1 = appDomain.Load(typeof(JSonReaderException).Assembly.GetName());
            var a2 = appDomain.Load(typeof(BayeuxException).Assembly.GetName());
            var a3 = appDomain.Load(typeof(ServiceCreationException).Assembly.GetName());

            Assert.IsNotNull(a1);
            Assert.IsNotNull(a2);
            Assert.IsNotNull(a3);

            thrower = (Rethrower)appDomain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().GetName().CodeBase, typeof(Rethrower).FullName);
        }
 /// <summary>
 /// Executes the action on the specified controller.
 /// </summary>
 /// <param name="controllerContext">The controller context.</param>
 /// <param name="actionName">Name of the action.</param>
 /// <param name="modelBinders">The model binders.</param>
 public override void ExecuteAction(ControllerContext controllerContext, string actionName, ModelBinderDictionary modelBinders)
 {
     var dispatcher = controllerContext.Request.Navigator.Dispatcher;
     ThreadPool.QueueUserWorkItem(
         delegate
             {
                 Thread.CurrentThread.Name = string.Format("Navigation request: {0}", controllerContext.Request);
                 try
                 {
                     ExecuteBase(controllerContext, actionName, modelBinders);
                 }
                 catch (Exception ex)
                 {
                     var rethrower = new Rethrower(
                         string.Format("An exception occurred when attempting to asynchronously execute the request '{0}'. {1}", controllerContext.Request, ex.Message), 
                         ex);
                     dispatcher.Dispatch(rethrower.RethrowOnDispatchThread);
                 }
             });
 }
        /// <summary>
        /// Executes the action on the specified controller.
        /// </summary>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="actionName">Name of the action.</param>
        /// <param name="modelBinders">The model binders.</param>
        public override void ExecuteAction(ControllerContext controllerContext, string actionName, ModelBinderDictionary modelBinders)
        {
            var dispatcher = controllerContext.Request.Navigator.Dispatcher;

            ThreadPool.QueueUserWorkItem(
                delegate
            {
                Thread.CurrentThread.Name = string.Format("Navigation request: {0}", controllerContext.Request);
                try
                {
                    ExecuteBase(controllerContext, actionName, modelBinders);
                }
                catch (Exception ex)
                {
                    var rethrower = new Rethrower(
                        string.Format("An exception occurred when attempting to asynchronously execute the request '{0}'. {1}", controllerContext.Request, ex.Message),
                        ex);
                    dispatcher.Dispatch(rethrower.RethrowOnDispatchThread);
                }
            });
        }