C# OnReceived Event is fired twice -


i'm relatively new c# , had stumbled across issue onreceived event triggered twice first time doesn't update subscriber instead update on second times. below of codes used in program. appreciate if can have , tell me cause at.

i have this.

public tcpmain()     {         socketservice.tcpclient.onconnected += new socketservice.tcpclient.onconnectedhandler(client_onconnected);         socketservice.tcpclient.ondatareceived += new socketservice.tcpclient.ondatareceivedhandler(client_ondatareceived);         socketservice.tcpclient.ondisconnected += new socketservice.tcpclient.ondisconnectedhandler(client_ondisconnected);         socketservice.tcpclient.onstatus += new socketservice.tcpclient.onstatushandler(client_onstatus);         socketservice.tcpclient.onstatus2 += new socketservice.tcpclient.onstatus2handler(client_onstatus2);     }      public tcpmain(string remoteserverip, int remoteserverport, int remoteserverport2, string localip = "", int localport = 0)     {         this.remoteserverip = remoteserverip;         this.remoteserverport = remoteserverport;         this.remoteserverport2 = remoteserverport2;         this.localip = localip;         this.localport = localport;          socketservice.tcpclient.onconnected += new socketservice.tcpclient.onconnectedhandler(client_onconnected);         socketservice.tcpclient.ondatareceived += new socketservice.tcpclient.ondatareceivedhandler(client_ondatareceived);         socketservice.tcpclient.ondisconnected += new socketservice.tcpclient.ondisconnectedhandler(client_ondisconnected);         socketservice.tcpclient.onstatus += new socketservice.tcpclient.onstatushandler(client_onstatus);         socketservice.tcpclient.onstatus2 += new socketservice.tcpclient.onstatus2handler(client_onstatus2);     } 

then have created on virtual

    public delegate void onreceivedhandler(string key, string value);     public event onreceivedhandler onreceived;      public delegate void ondatareceivedhandler(string message);     public event ondatareceivedhandler ondatareceived;      public virtual void raiseondatareceived(string message)     {         if (ondatareceived != null)             ondatareceived(message);     } 

and when received event triggered, following function called

    void client_ondatareceived(string message)     {         try         {             raiseondatareceived(message);             message = message.trimend();             string[] _strparts = null;         }      } 

when new message arrived, client_ondatareceived triggered , after raiseondatareceived called tcpmain reference virtual. problem when reached virtual, ondatareceived = null return client , execute rest of coding. second time event triggered, ondatareceived = there 1 message sent @ time.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -