异步刷新

 


/// <summary>
/// AsynchronousLoading class
/// </summary>
public static class AsynchronousLoading
{
/// <summary>
/// AsyncInvokeHandler delegate
/// </summary>
/// <returns>object</returns>
public delegate object AsyncInvokeHandler();
/// <summary>
/// AsyncInvokeCallbackHandler
/// </summary>
/// <param name="result">object</param>
/// <param name="e">Exception</param>
public delegate void AsyncInvokeCallbackHandler(object result, Exception e);

/// <summary>
/// Async invoke method
/// </summary>
/// <param name="handler">AsyncInvokeHandler</param>
/// <param name="callback">AsyncInvokeCallbackHandler</param>
public static void AsyncInvoke(AsyncInvokeHandler handler, AsyncInvokeCallbackHandler callback)
{
System.Threading.Thread t = new System.Threading.Thread(() =>
{
try
{
callback(handler(), null);
}
catch (Exception e)
{
Log.LogError(e);
callback(null, e);
}
});
t.IsBackground = true;
t.Start();
}

}


//*****************************************************************************
#region AsynchronousLoading

AsynchronousLoading.AsyncInvoke(() =>
{
#region

return updateAction.ExecuteDownloadDataFromDrFirst(patient, CurrentUserInfo.CurrentSysUser);

#endregion

}, (result, ex) =>
{
if (ex != null)
{
Dispatcher.Invoke(new System.Threading.ThreadStart(() =>
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}));
}
bool bResult = (bool)result;
if (bResult)
{
Dispatcher.Invoke(new System.Threading.ThreadStart(() =>
{
MessageBox.Show("Download data successfully!", "Attention", MessageBoxButton.OK, MessageBoxImage.Information);
SystemManager.RefreshHealthcareAssociatedView(pChekIn);
}));
}
else
{
Dispatcher.Invoke(new System.Threading.ThreadStart(() =>
{
MessageBox.Show("Download data failed! Please make sure the internet is useable!",
"Error", MessageBoxButton.OK, MessageBoxImage.Error);
}));
}
});

#endregion AsynchronousLoading

 

posted @ 2014-01-23 18:48  quietwalk  阅读(683)  评论(0编辑  收藏  举报