MonodroidStockPortfolio/MonoStockPortfolio/Framework/OnGuiThreadAttribute.cs

23 lines
No EOL
662 B
C#

using Android.App;
using Android.Util;
using PostSharp.Aspects;
namespace MonoStockPortfolio.Framework
{
public class OnGuiThreadAttribute : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
var activity = args.Instance as Activity;
if (activity == null)
{
Log.Error("OnGuiThreadAttribute", "OnGuiThreadAttribute can only be used on methods within an Activity");
args.Proceed();
}
else
{
activity.RunOnUiThread(args.Proceed);
}
}
}
}