Skip to content

Instantly share code, notes, and snippets.

@wilfrem
Created July 1, 2013 17:07
Show Gist options
  • Save wilfrem/5902665 to your computer and use it in GitHub Desktop.
Save wilfrem/5902665 to your computer and use it in GitHub Desktop.
チャタリング防止機構。Monitor使うのはやめたほうがいいかな……
/// <summary>
/// AndroidUIスレッドのチャタリングを防ぐための機構
/// </summary>
public static class AntiUIChattering
{
public static EventHandler<T> WrapHandlerWithArgs<T>(EventHandler<T> funcForUIEvent)
{
return (sender, e)=>{
if(!Monitor.TryEnter(funcForUIEvent))
return;
try{
funcForUIEvent(sender, e);
}finally{
Monitor.Exit(funcForUIEvent);
}
};
}
public static EventHandler WrapHandlerNoArgs(EventHandler funcForUIEvent)
{
return (sender, e)=>{
if(!Monitor.TryEnter(funcForUIEvent))
return;
try{
funcForUIEvent(sender, e);
}finally{
Monitor.Exit(funcForUIEvent);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment