I’m running across a very frustrating problem that I’m really hoping someone can help me with. I have made an application that controls another application via TCP/IP commands. (I am having no problem with the functionality of the application.) One of the things my program needs to do is to update the values of different fields in the other application as soon as they’re changed on mine. To do this, I use the
Sub ControlName_ValueChanged(sender As Object, e As System.EventArgs) Handles _
ControlName.ValueChanged
sendData(dataToSend,destination)
End Sub
format. The subroutine involves TCP/IP transactions, which are not initiated until after the user starts it manually on my app. The problem I’m running into is that when my startup form loads, it immediately calls all of the *.ValueChanged subroutines, effectively locking up my application. Can someone explain why this is happening and how to stop it?
If you want to stop UI blocking, you could make the
sendDataimplementation use asynchronous calls (usually realised asBeginSend/EndSendmethod pairs on the type.I’m not sure why the event handler is doing this off-hand (possibly because after the object is created, the value is set to some default after the event handler has been registered).
One way to stop it is to manually wire up the
ValueChangedevent handler after you have loaded your form, instead of doing it in the designer via the designer.cs file.Alternatively, have a
suppressEventsbool flag that you can toggle on and off, and amend your method to listen to the flag:I have no idea if this is valid VB, I do C#, but you get the idea.