create a new istance, and after close it?

ssormanni

Member
Joined
Nov 12, 2010
Messages
5
Location
Italy
Programming Experience
Beginner
Could I create a new istance, and after close it?

IDEA = New TcpClient("192.168.1.101", 502)
......
IDEA.Close()

Thanks, Stefano
 
I don't understand the question. Perhaps you could explain some more?
 
Sorry if I'm not explain better my thought.... I've modified my SUB as below.... and in every timer before to Call the Sub, I close the Istance:

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
IDEA.Close()
Call PLC()
..........
Public Sub PLC()
'attivo il timer
Timer3.Enabled = True
Timer1.Enabled = True
Try
IDEA = New TcpClient("192.168.1.101", 502)
Catch Errore As Exception
Timer1.Enabled = False
'
Timer3.Enabled = False
Timer4.Enabled = False
Timer5.Enabled = False
Timer6.Enabled = False
Timer7.Enabled = False
Timer8.Enabled = False
Timer9.Enabled = False
Timer10.Enabled = False
Timer11.Enabled = False
Timer12.Enabled = False
MsgBox("Can't connect PLC Socket")
Sleep(10000)
IDEA.Close()
Call PLC()
End Try
Premium = Modbus.Device.ModbusIpMaster.CreateIp(IDEA)
End Sub

Hope to be more clear now...

Thanks
 
Hope to be more clear now...
No, not at all.

Why do you close and connect again if there is already an established connection? Of course you can do it, but then you should move the Close call to within the Try block where the connection is created.
If no connection could be made there would be no TcpClient instance, and nothing to call close on, since the constructor would have thrown exception.

12 Timers? :) lol
 
Back
Top