MSNPSHARP发送消息时必须建立会话才能发送,做的时候,网上居然没有找到。。。。。而这个是做MSN机器人需要的,否则光等用户主动发消息来不能主动发送的话够傻的。贴段代码吧,类名字和SAMPLE不同,其实一样的。原理很简单,如果会话存在则用会话,否则新建一个。
private void SendText(string accountname,string text)
{
try
{
foreach (ConversationHandle conv in ConversationHandles)
{
int res = conv.CanAttach(accountname);
if (res != -1)
{
conv.SendText(text);
return;
}
}
ConversationHandle conversationHandle = new ConversationHandle(null, this, accountname);
ConversationHandles.Add(conversationHandle);
conversationHandle.SendText(text);
}
catch(Exception ex)
{
ShowLog("SendText错误:" + ex.Message);
}
}