i’m developing a microsoft WPF instant message application based on XMPP using agsXMPP library. there are many events in the agsXMPP like OnXmppConnectionStateChanged,OnLogin,OnPresence and so on, and on the other hand, because of the WPF thread mode, i have to handle event through UI’s Dispatcher.Invoke() method,it exactly looks like this:
void handleRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
{
STP_FriendsHolder.Dispatcher.BeginInvoke(new Action(delegate
{
RosterItemControl rosterItem = new RosterItemControl();
rosterItem.RosterItemName = item.Jid.User;
rosterItem.Margin = new Thickness(0);
STP_FriendsHolder.Children.Add(rosterItem);
}));
}
i use anonymous method in almost every BeginInvoke/Invoke method,because i don’t want to create too many named methods everywhere(as i think this is not so ‘clean’). But i’m afraid it’s not so in a OOP way, and these anonymous methods are very difficult to maintain. So,how can i code in a better way in this situation?
i’m sorry for my poor English,i have tried my best to make it clear^_^
thanks!
NewRosterItem(RosterItem item)