mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-29 11:17:07 +00:00
42 lines
No EOL
1.4 KiB
C#
42 lines
No EOL
1.4 KiB
C#
using System;
|
|
using System.Threading;
|
|
using Android.App;
|
|
using PostSharp.Aspects;
|
|
|
|
namespace MonoStockPortfolio.Framework
|
|
{
|
|
public class OnWorkerThreadAttribute : MethodInterceptionAspect
|
|
{
|
|
private ProgressDialog _progressDialog;
|
|
|
|
public override void OnInvoke(MethodInterceptionArgs args)
|
|
{
|
|
var activity = args.Instance as Activity;
|
|
if(activity == null) throw new Exception("OnWorkerThread can only be used on methods in Activity classes");
|
|
|
|
ShowProgressDialog(activity);
|
|
ThreadPool.QueueUserWorkItem(delegate
|
|
{
|
|
args.Proceed();
|
|
activity.RunOnUiThread(DismissProgressDialog);
|
|
});
|
|
}
|
|
|
|
private void ShowProgressDialog(Activity activity)
|
|
{
|
|
if (_progressDialog == null)
|
|
{
|
|
var pd = new ProgressDialog(activity);
|
|
pd.SetMessage("Loading...Please wait...");
|
|
pd.SetProgressStyle(ProgressDialogStyle.Spinner);
|
|
_progressDialog = pd;
|
|
}
|
|
_progressDialog.Show();
|
|
}
|
|
|
|
private void DismissProgressDialog()
|
|
{
|
|
_progressDialog.Dismiss();
|
|
}
|
|
}
|
|
} |