小马

现在是零将来是无限

导航

对于事件不能调用BeginInvoke,可改用另外一层包装

事件类型: 错误
事件来源: WISP CmppRelay
事件种类: 无
事件 ID: 38
日期:  2005-11-28
事件:  18:54:45
用户:  N/A
计算机: SERVER1
描述:
调用类"Sinosky.Cmpp.CmppSubmitHandler"的方法"System.IAsyncResult BeginInvoke(Sinosky.Cmpp.Message.CmppSubmit, System.AsyncCallback, System.Object)"时发生异常,详细信息:
System.ArgumentException: 该委托必须有一个目标(且仅有一个目标)。
   at Sinosky.Cmpp.CmppSubmitHandler.BeginInvoke(CmppSubmit message, AsyncCallback callback, Object object)
   at Sinosky.Cmpp.CmppRelay.Send(CmppSubmit message) in C:\Documents and Settings\leon\My Documents\Visual Studio Projects\Sinosky.Cmpp\CmppRelay.cs:line 41

有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。

修改后的代码如下:

/// <summary>
        
/// 异步发送下行消息。
        
/// </summary>
        
/// <param name="msg">下行消息</param>

        public void Send(Message.CmppSubmit message)
        
{
            
try
            
{
                CmppSubmitHandler handler 
= new CmppSubmitHandler(this.SendInternal);


                handler.BeginInvoke(message,
new AsyncCallback(this.SendCallback),message);
    
            }

            
catch(Exception ex)
            
{
                Sinosky.Diagnostics.EventLog.WriteEntry(
this,ex);
            }

        }


        
private void SendInternal(Message.CmppSubmit message)
        
{
            
try
            
{
                
if(this.SubmitDispatched!=null)
                
{
                    
this.SubmitDispatched(message);
                }

                
else
                
{
                    Console.WriteLine(
"\n^^^^Throw " + message.ToString());
                }

            }

            
catch(Exception e)
            
{
                Sinosky.Diagnostics.EventLog.WriteEntry(
this,e);
            }

        }



        
private void SendCallback(System.IAsyncResult ar)
        
{
            Message.CmppSubmit message 
= ar.AsyncState as Message.CmppSubmit;

#if DEBUG
            
if(message!=null)
            
{
                Console.WriteLine(
"\n<<<<Dispatch " + message.ToString());
            }

#endif
        }

posted on 2005-11-28 19:14  mahope  阅读(1817)  评论(0编辑  收藏  举报