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;
}));
});
}