mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-29 11:17:07 +00:00
32 lines
No EOL
1.1 KiB
C#
32 lines
No EOL
1.1 KiB
C#
using System;
|
|
using System.Threading;
|
|
using Android.App;
|
|
using PostSharp.Aspects;
|
|
|
|
namespace MonoStockPortfolio.Framework
|
|
{
|
|
public class OnWorkerThreadAttribute : MethodInterceptionAspect
|
|
{
|
|
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");
|
|
|
|
var pd = ShowProgressDialog(activity);
|
|
pd.Show();
|
|
ThreadPool.QueueUserWorkItem(delegate
|
|
{
|
|
args.Proceed();
|
|
activity.RunOnUiThread(pd.Dismiss);
|
|
});
|
|
}
|
|
|
|
private static ProgressDialog ShowProgressDialog(Activity activity)
|
|
{
|
|
var pd = new ProgressDialog(activity);
|
|
pd.SetMessage("Loading...Please wait...");
|
|
pd.SetProgressStyle(ProgressDialogStyle.Spinner);
|
|
return pd;
|
|
}
|
|
}
|
|
} |