zoukankan      html  css  js  c++  java
  • AsynchronousLoading

    Class

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

     

    namespace rEHRGrowthChart

    {

        public static class AsynchronousLoading

        {

            public delegate object AsyncInvokeHandler();

            public delegate void AsyncInvokeCallbackHandler(object result, Exception e);

     

            public static void AsyncInvoke(AsyncInvokeHandler handler, AsyncInvokeCallbackHandler callback)

            {

                System.Threading.Thread t = new System.Threading.Thread(() =>

                {

                    try

                    {

                        callback(handler(), null);

                    }

                    catch (Exception e)

                    {

                        GrowthChartLog.LogInfo(e.Message);

                        callback(null, e);

                    }

                });

                t.IsBackground = true;

                t.Start();

            }

     

        }

    }

     

    How to use it?

    private void Window_Loaded(object sender, RoutedEventArgs e)

            {

                AsynchronousLoading.AsyncInvoke(() =>

                {

                    #region

     

                    //Data.IUseCaseAction useCaseAction = App.ActionFactory.CreateUseCaseAction();

                    //IList<TurfUseCaseFolder> useCaseFolderList = useCaseAction.RetrieveUseCaseFolders(new TurfUseCaseFolder() { Parent = null });

                    //return useCaseFolderList;

     

                    return null;

     

                    #endregion

     

                }, (result, ex) =>

                {

                    if (ex != null)

                    {

                        GrowthChartLog.LogInfo(ex.Message);

                        Dispatcher.Invoke(new System.Threading.ThreadStart(() =>

                        {

                            MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                            return;

                       }));

                    }

                    //IList<TurfUseCaseFolder> useCaseFolderList = (IList<TurfUseCaseFolder>)result;

                    Dispatcher.Invoke(new System.Threading.ThreadStart(() =>

                    {

                        //UseCaseList.ItemsSource = useCaseFolderList;

                        //string[] ruleList = new string[]

                        //{

                        //    Constant.RuleName_ProductName,

                        //    Constant.RuleName_ProjectName,

                        //    Constant.RuleName_FolerName,

                        //    Constant.RuleName_CreatorInitial,

                        //    Constant.RuleName_Time,

                        //    Constant.RuleName_Type,

                        //    Constant.RuleName_FileCount

                       //};

                        //ImageRulesList.ItemsSource = ruleList;

                        //VedioRulesList.ItemsSource = ruleList;

                        //ProblemRulesList.ItemsSource = ruleList;

                    }));

                });

            }

  • 相关阅读:
    leetcode74
    leetcode59
    leetcode1283
    0079. Word Search (M)
    0067. Add Binary (E)
    0203. Remove Linked List Elements (E)
    用async 解放你的大脑
    Python 类属性和方法
    Python 类装饰器
    Python 装饰器
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2492214.html
Copyright © 2011-2022 走看看