Exemplo n.º 1
0
        /// <summary>
        /// 判断当前操作是否需要调用Invoke[返回值:true:调用Invoke;false:不需要]
        /// </summary>
        /// <param name="dispatcher">判断的对象</param>
        /// <returns>返回值:true:调用Invoke;false:不需要</returns>
        public static bool InvokeRequired(this System.Windows.Threading.DispatcherObject dispatcher)
        {
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            return(!dispatcher.Dispatcher.CheckAccess());
        }
Exemplo n.º 2
0
        /*
         * let execInThread f =
         * if Threading.Thread.CurrentThread.IsBackground then // modo rapido per capire se siamo già in un thread
         *      f ()
         * else
         *      let body () =
         *              try
         *                      f()
         *              with
         | ecc  ->
         |                   showCrashDialog ecc None "execInThread - "
         |      (  // faccio partire il thread
         |      let th = new System.Threading.Thread(body)
         |      th.CurrentUICulture <-  new Globalization.CultureInfo(g_lang)
         |      th.Priority <- Threading.ThreadPriority.Normal
         |      th.IsBackground <- true
         |      th.Start ()
         |      )
         |
         *
         * */


        /// <summary>
        /// Execute a given piece of code in background, in a thread, in order to return quickly.
        /// </summary>
        /// <param name="dobj"></param>
        /// <param name="a"></param>
        //public static void execInThread(Action a)
        //{
        //    if (System.Threading.Thread.CurrentThread.IsBackground)
        //    {
        //        // we are already in a thread, no need to start another.

        //        a.Invoke();
        //    }
        //    else
        //    {

        //        var th = new Task((() =>
        //        {
        //            try
        //            {
        //                a.Invoke();
        //            }
        //            catch (Exception e)
        //            {
        //                Log.log(">>> execInThread: exception:" + Utils.stringOfException(e));
        //            }

        //        }));

        //        th.Start();
        //    }

        //}

        //public static void execInThreadForceNewThread(Action a)
        //{

        //    var th = new Task((() =>
        //    {
        //        try
        //        {
        //            a.Invoke();
        //        }
        //        catch (Exception e)
        //        {
        //            Log.log(">>> execInThreadForceNewThread: exception:" + Utils.stringOfException(e));
        //        }

        //    }));

        //    // th.CurrentUICulture = ...
        //    //th.Priority = ThreadPriority.Normal;
        //    //th.IsBackground = true;
        //    th.Start();

        //}
        public static void gui(System.Windows.Threading.DispatcherObject dobj, Action a)
        {
            var aWrapped = new Action(() =>
            {
                try
                {
                    a();
                }
                catch (Exception e)
                {
                    var crashId    = "outlook-addin: crash in gui fun";
                    var stackTrace = ThisAddIn.AssemblyVer_safe() + CrashReportFsharp.stringOfException(e);
                    var str        = crashId + stackTrace;
                    Log.log(str);
                }
            });

            dobj.Dispatcher.Invoke(aWrapped, null);
        }
Exemplo n.º 3
0
 public static System.IObservable <TSource> SubscribeOn <TSource>(this System.IObservable <TSource> source, System.Windows.Threading.DispatcherObject dispatcherObject)
 {
     throw null;
 }