|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
actions done twice but only one trigger?event is triggered (only once) I get two packets sent. I am supposed to only get one packet. I used the MS SDK as the basis for this program. What am I doing wrong? Thanks, Ben Namespace Microsoft.Samples Module LogMonitor Dim WithEvents evtSec As New EventLog("Security") Public Sub Main() evtSec.MachineName = "." AddHandler evtSec.EntryWritten, AddressOf OnEntryWritten evtSec.EnableRaisingEvents = True While (Console.Read() <> 113) System.Threading.Thread.Sleep(500) End While End Sub Sub OnEntryWritten(ByVal source As Object, ByVal e As EntryWrittenEventArgs) Handles evtApp.EntryWritten, evtSec.EntryWritten, evtSys.EntryWritten Try sendinfo(e, "192.168.1.33", "44000") Catch se As Exception MsgBox(se.ToString(), , "LogMonitor Error") End Try End Sub Sub sendinfo(ByVal e As EntryWrittenEventArgs, ByVal servername As String, ByVal portnum As String) Dim sendbuffer As [Byte]() Dim sendstring As String Dim hostname As String = System.Net.Dns.GetHostName() Dim tcpClient As New System.Net.Sockets.TcpClient() tcpClient.Connect(servername, portnum) Dim networkStream As System.Net.Sockets.NetworkStream = tcpClient.GetStream() sendstring = "Check my security log" sendbuffer = System.Text.Encoding.ASCII.GetBytes(sendstring) networkStream.Write(sendbuffer, 0, sendbuffer.Length) tcpClient.Close() End Sub End Module End Namespace "Ben" <ben553***@yahoo.com> wrote in message I don't know what the problem was, but coping the code to a new project news:uWxWODXjGHA.3496@TK2MSFTNGP02.phx.gbl... >I am sending a packet to a server when an event is triggered. When the >event is triggered (only once) I get two packets sent. I am supposed to >only get one packet. I used the MS SDK as the basis for this program. >What am I doing wrong? > > Thanks, > Ben fixed it. Ben wrote:
> I am sending a packet to a server when an event is triggered. When the It looks like you are wiring up the event handler twice. Once in Sub> event is triggered (only once) I get two packets sent. I am supposed to only > get one packet. I used the MS SDK as the basis for this program. What am I > doing wrong? Main where you call AddHandler and again when you declare the OnEntryWritten sub using the Handles keyword. You don't need both. Either use WithEvent and the Handles keyword, or use AddHandler alone. > Public Sub Main() First event handler wired up here: ^^^^^> evtSec.MachineName = "." > AddHandler evtSec.EntryWritten, AddressOf OnEntryWritten > End Sub Second event handler wired up here using the Handles keyword: ^^^> > Sub OnEntryWritten(ByVal source As Object, ByVal e As > EntryWrittenEventArgs) Handles evtApp.EntryWritten, evtSec.EntryWritten, > evtSys.EntryWritten
Error converting FILETIME to DateTime
Report viewer Page margins problem Read text-segment from binary file line breaks Where is Page.RegisterClientScriptBlock Available? richtextbox selectedtext bold upper .... how to find out Tabindex is driving me nuts!!! Screen coordinates of selected datagridview cells left and top borders creating code on the fly at runtime How to get all files from http server |
|||||||||||||||||||||||