473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

actions done twice but only one trigger?

Ben
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

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
Jun 11 '06 #1
2 1005
Ben
"Ben" <be*******@yahoo.com> wrote in message
news:uW**************@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


I don't know what the problem was, but coping the code to a new project
fixed it.
Jun 11 '06 #2
Ben wrote:
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?
It looks like you are wiring up the event handler twice. Once in Sub
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()
evtSec.MachineName = "."
AddHandler evtSec.EntryWritten, AddressOf OnEntryWritten
First event handler wired up here: ^^^^^

End Sub

Sub OnEntryWritten(ByVal source As Object, ByVal e As
EntryWrittenEventArgs) Handles evtApp.EntryWritten, evtSec.EntryWritten,
evtSys.EntryWritten


Second event handler wired up here using the Handles keyword: ^^^

Jun 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
When we refresh the page (F5, or icon in browser), it will first trigger ONUNLOAD event and then trigger ONLOAD event. When we close the browser (X on right top icon), it will trigger ONUNLOAD...
0
by: pdvluca | last post by:
Hi all, I'm quite new to postgresql, so please forgive me if these are stupid questions, but I couldn't find answers. I'm using versione 7.3.4 (i can't upgrade, sorry). I've written a...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
3
by: =?Utf-8?B?amRrYzRk?= | last post by:
I have been designing an application in Visual Studio 2005, and just about everything is working, except all of my events run twice. They run through correctly, but then they randomly run through...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.