Multithreading and splitting the workload - vb.net

So I created a spotify checker to check a list of accounts on their logins and current subscription, This works fine, but it's only running on one thread and that in my opinion is really slow. So I started searching around for multithreading (I am pretty new to vb.net and am trying to learn this way.) But everything I threw at it would just run all threads seperately on the same accounts without any difference in results, just that they were printed out multiple times.
The code for the sub Login:
Public Sub Login()
Dim index As Integer = 0
While index < Combos.Count
Dim str() As String = Combos(index).Split(":")
Using req As New HttpRequest
req.UserAgent = Http.ChromeUserAgent
req.Cookies = New CookieDictionary()
req.Proxy = Nothing
req.IgnoreProtocolErrors = True
req.Get("https://accounts.spotify.com/en-US/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F")
Dim token As String = req.Cookies.ToString
Dim csrf As String = Regex.Match(token, "csrf_token=(\S+)").Groups(1).ToString
req.Referer = "https://accounts.spotify.com/en-US/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F"
req.AddHeader("Cookie", "csrf_token=" + csrf + "; __bon=MHwwfDQ1MzY4Nzk4M3wxOTA1NDg5NTI4NnwxfDF8MXwx; fb_continue=https%3A%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F; remember=false")
req.AddParam("remember", "false")
req.AddParam("username", str(0))
req.AddParam("password", str(1))
req.AddParam("captcha_token", "")
req.AddParam("csrf_token", csrf)
Dim respo As String = req.Post("https://accounts.spotify.com/api/login").ToString
If respo.Contains("displayName") Then
Dim IT As New ListViewItem
IT.Text = str(0)
IT.SubItems.Add(str(1))
Dim html As String = req.Post("https://spotify.com/account/subscription/").ToString
Dim Info As Match = Regex.Match(html, "<h3.*>(.*)<\/h3>")
Dim Type As String = Info.Groups(1).Value
If Type.Contains("Spotify Premium") Then
IT.SubItems.Add("Spotify Premium")
ListView1.Items.Add(IT)
Label3.Text += 1
Label1.Text += 1
ElseIf Type.Contains("Premium for Family") Then
IT.SubItems.Add("Spotify Premium for Family")
ListView1.Items.Add(IT)
Label3.Text += 1
Label1.Text += 1
Else
If StrafeCheckBox1.Checked = False Then
Label2.Text += 1
Else
IT.SubItems.Add("Free")
ListView1.Items.Add(IT)
Label1.Text += 1
End If
End If
Else
Label2.Text += 1
End If
End Using
index += 1
StrafeProgressBar1.Value = index
If index = Combos.Count Then
MsgBox("Done, successfull logins: " + Label1.Text)
End If
End While
End Sub
Code for the start button:
Private Sub LoginBTN_Click(sender As Object, e As EventArgs) Handles StartBTN.Click
Dim IH As New Thread(AddressOf Login) : IH.Start()
StrafeProgressBar1.Maximum = Combos.Count
End Sub
So what I basically want to know, is how I get the threads to split the
workload evenly. and finish the job a lot quicker.
All help is appreciated.

Related

Ping the network quickly

good day!
Tell me how you can quickly ping the entire network?
There is the following code that scans the network.
Public Sub Scan(ByVal subnet As String)
Dim myPing As Ping
Dim reply As PingReply
Dim addr As IPAddress
Dim host As IPHostEntry
Dim active_addr As Integer = 0
ProgressBar1.Maximum = 254
ProgressBar1.Value = 0
ListView1.Items.Clear()
For i As Integer = 1 To 254
Dim subnetn As String = "." & i.ToString()
myPing = New Ping()
reply = myPing.Send(subnet & subnetn, 900)
Label3.ForeColor = Color.Green
Label3.Text = "Scan: " & subnet & subnetn
If reply.Status = IPStatus.Success Then
Try
addr = IPAddress.Parse(subnet & subnetn)
host = Dns.GetHostEntry(addr)
If My.Computer.Network.Ping(host.HostName, 10) Then
ListView1.Items.Add(New ListViewItem(New String() {subnet & subnetn, host.HostName, "True"}))
Else
ListView1.Items.Add(New ListViewItem(New String() {subnet & subnetn, host.HostName, "False"}))
End If
Catch
ListView1.Items.Add(New ListViewItem(New String() {subnet & subnetn, " ", "False"}))
End Try
active_addr += 1
End If
ProgressBar1.Value += 1
Label5.Text = Math.Round((ProgressBar1.Value * 100) / 254, 0, MidpointRounding.AwayFromZero) & " %"
')
ListView1.Items((ListView1.Items.Count - 1)).EnsureVisible()
ListView1.Items((ListView1.Items.Count - 1)).Selected = True
Next i
ListView1.Items(0).Focused = True
ListView1.Items(0).Selected = True
End Sub
But it takes a very long time to scan the network. Tell me, is it possible to do it faster?
And can I add the device's MAC address when scanning the network?
================================================================
Found a solution that quickly scans the network (a given range of ip addresses).
Tell me. how to add to this code to display the hostname and the MAC address? and add a ProgressBar to show the scan percentage.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Ping("192.168.1.28", "175")
End Sub
Private Async Function Ping(startIP As String, endIP As String) As Task
Dim start As IPAddress = IPAddress.Parse(startIP)
Dim bytes = start.GetAddressBytes()
Dim leastSigByte = start.GetAddressBytes().Last
Dim range = endIP - leastSigByte
Dim pingReplyTasks = Enumerable.Range(leastSigByte, range).Select(Function(x)
Dim p = New Ping()
Dim bb = start.GetAddressBytes()
bb(3) = CByte(x)
Dim destIp = New IPAddress(bb)
Dim pingResultTask = p.SendPingAsync(destIp)
Return New With {
Key pingResultTask,
Key .addr = destIp
}
End Function).ToList()
Await Task.WhenAll(pingReplyTasks.Select(Function(x) x.pingResultTask))
For Each pr In pingReplyTasks
Dim tsk = pr.pingResultTask
Dim pingResult = tsk.Result
Dim ip = pr.addr
'
DataGridView1.Rows.Add(ip, pingResult.RoundtripTime, pingResult.Status)
Next pr
End Function

Import very big text file into sql. Speed problem

I must import a big text file into sql database.
The text file contains some 5 million of rows. :D
My pc is old ed I use vb.net, but is only for one shot.
When import started, the code read and entered 100 lines for second.
Is slowly but for one shot is not a problem.
Now, at 300.000 lines readed, it work ar 8 lines for second. :(
The goal is far away....
The strange thing is, if I start from first line and in the database have 300.000 record, the speed is fast (100 L/s) even though I check that I don't have the record.
In sql I created a cluster index.
This is the vb.net code into BackgroundWorker DoWork:
Private Sub Bw_DoWork(sender As Object, e As DoWorkEventArgs)
Dim d = DirectCast(e.Argument, BwData).Path
Dim s = DirectCast(e.Argument, BwData).Start
Dim reader As IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(d)
Dim l As String
Dim lineIndex As Integer = 0
Dim lineStart As Integer = 0
Dim part As String() = Nothing
Try
Using ctx = New ContentsDBEntities
Dim rowN = s 'Math.Max(ctx.xHamster.Count - 100, 1)
Do
l = reader.ReadLine
If l Is Nothing Then
Exit Do
End If
part = l.Split("|")
If Bw.CancellationPending Then Exit Do
If lineIndex >= rowN AndAlso part.Length >= 14 Then
If lineIndex = rowN Then
lineStart = lineIndex
startAt = Now
End If
Dim vId = part(0)
If IsNumeric(vId) Then
Dim there = (From c In ctx.xHamster Where c.VideoId = vId Select c).FirstOrDefault
If there Is Nothing Then
Dim r = New xHamster With {
.VideoId = vId,
.Url = part(1),
.Umbed_Url = part(2),
.Title = part(3),
.Duration = StringToSec(part(4)),
.dateAdded = Date.Parse(part(5)),
.Thumb = part(6),
.Channels = part(7),
.Pornstars = part(8),
.MaxResolution = part(9),
.Orientation = part(10),
.Title_RU = part(11),
.Username = part(12),
.Description = part(13)}
ctx.xHamster.Add(r)
If lineIndex Mod 100 = 0 Then
ctx.SaveChanges()
End If
End If
End If
End If
lineIndex += 1
DirectCast(sender, BackgroundWorker).ReportProgress(lineIndex, lineStart)
Loop Until l Is Nothing
reader.Close()
ctx.SaveChanges()
End Using
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
Do you have a trick for me?
Why does the speed decrease?
Thank you
Luca

I want to make a maths quiz on vb.net that uses bracket questions

So I've used visual basics (vb.net) for a bit now and understand some stuff. Right now I want to make a maths quiz that when I click a button it takes me to a new form and starts the quiz. When the quiz starts I want it so it gives the user random numbers and the user needs to answer it in a textbox and if correct it moves on to the next question (Basic, I should be able to do). IMPORTANT - my question is, there's a maths rule called BODMAS (Bracket.Order.Division.Multiply.Add.Subtract) and I want to add this rule into my coding instead of doing regular simple maths...
EXAMPLE question is 2 x (2+3) - 1 = ?
2 x 5 - 1 = ?
10 - 1 = ?
9 = 9
person writes answer to textbox and moves to next similar question
This is my first time using this but I wanted to write in-depth so people can understand. Please help me if you find a video explaining what I'm looking for or if someone has a file with a similar code I could download would be greatly appreciated!
Basically,you need to determine the range of numbers you use, and then match them randomly among '*', '/', '+', '-'. Then randomly insert brackets into it.
Private codeStr As String
Private Function GenerateMathsQuiz() As String
Dim r As Random = New Random()
Dim builder As StringBuilder = New StringBuilder()
'The maximum number of operations is five, and you can increase the number [5] to increase the difficulty
Dim numOfOperand As Integer = r.[Next](1, 5)
Dim numofBrackets As Integer = r.[Next](0, 2)
Dim randomNumber As Integer
For i As Integer = 0 To numOfOperand - 1
'All numbers will be random between 1 and 10
randomNumber = r.[Next](1, 10)
builder.Append(randomNumber)
Dim randomOperand As Integer = r.[Next](1, 4)
Dim operand As String = Nothing
Select Case randomOperand
Case 1
operand = "+"
Case 2
operand = "-"
Case 3
operand = "*"
Case 4
operand = "/"
End Select
builder.Append(operand)
Next
randomNumber = r.[Next](1, 10)
builder.Append(randomNumber)
If numofBrackets = 1 Then
codeStr = InsertBrackets(builder.ToString())
Else
codeStr = builder.ToString()
End If
Return codeStr
End Function
Public Function InsertBrackets(ByVal source As String) As String
Dim rx As Regex = New Regex("\d+", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
Dim matches As MatchCollection = rx.Matches(source)
Dim count As Integer = matches.Count
Dim r As Random = New Random()
Dim numIndexFirst As Integer = r.[Next](0, count - 2)
Dim numIndexLast As Integer = r.[Next](1, count - 1)
While numIndexFirst >= numIndexLast
numIndexLast = r.[Next](1, count - 1)
End While
Dim result As String = source.Insert(matches(numIndexFirst).Index, "(")
result = result.Insert(matches(numIndexLast).Index + matches(numIndexLast).Length + 1, ")")
Return result
End Function
When you finish this, you will get a math quiz, then you need to know how to compile and run code at runtime.
Private Function GetResult(ByVal str As String) As String
Dim sb As StringBuilder = New StringBuilder("")
sb.Append("Namespace calculator" & vbCrLf)
sb.Append("Class calculate " & vbCrLf)
sb.Append("Public Function Main() As Integer " & vbCrLf)
sb.Append("Return " & str & vbCrLf)
sb.Append("End Function " & vbCrLf)
sb.Append("End Class " & vbCrLf)
sb.Append("End Namespace" & vbCrLf)
Dim CompilerParams As CompilerParameters = New CompilerParameters()
CompilerParams.GenerateInMemory = True
CompilerParams.TreatWarningsAsErrors = False
CompilerParams.GenerateExecutable = False
CompilerParams.CompilerOptions = "/optimize"
Dim references As String() = {"System.dll"}
CompilerParams.ReferencedAssemblies.AddRange(references)
Dim provider As VBCodeProvider = New VBCodeProvider()
Dim compile As CompilerResults = provider.CompileAssemblyFromSource(CompilerParams, sb.ToString())
If compile.Errors.HasErrors Then
Dim text As String = "Compile error: "
For Each ce As CompilerError In compile.Errors
text += "rn" & ce.ToString()
Next
Throw New Exception(text)
End If
Dim Instance = compile.CompiledAssembly.CreateInstance("calculator.calculate")
Dim type = Instance.GetType
Dim methodInfo = type.GetMethod("Main")
Return methodInfo.Invoke(Instance, Nothing).ToString()
End Function
Finally, you can use these methods like:
Private Sub GetMathQuizBtn_Click(sender As Object, e As EventArgs) Handles GetMathQuizBtn.Click
Label1.Text = GenerateMathsQuiz()
End Sub
Private Sub ResultBtn_Click(sender As Object, e As EventArgs) Handles ResultBtn.Click
If TextBox1.Text = GetResult(Label1.Text) Then
MessageBox.Show("bingo!")
TextBox1.Text = ""
Label1.Text = GenerateMathsQuiz()
Else
MessageBox.Show("result is wrong")
End If
End Sub
Result:

vb.net threading sub slower than call sub

I know this Question was already posted, but it was never really answered, or I did not understand the answer :)
My Problem is that when I call this Sub within the Thread, it takes about 4 sec to execute the code, but if I make a simple Call Sub (Like commented in Code) it takes about 450 ms.
I have a simple program with 2 Subs:
To report Progress on Main Form
To do some "For" Looping
Imports System.Data.SqlClient
Public Class Form1
Public Delegate Sub ProzentDelegate(ByVal Prozent As Double)
Dim G_I_Temp As Integer = 0
Dim G_S_Prüfziffer As String
Dim G_S_Präfix As String
Dim G_I_Zähler As Integer
Dim G_I_Stellen As Integer
Dim G_D_Step As Integer = 1
Dim G_I_Position As Integer
Dim DT_G_Prüftabelle As DataTable
Dim DR_G_Prüftabelle As DataRow
Dim thisLock As New Object
Dim conn As String = "Data Source=SR-SQLWVS;Initial Catalog=Barcode;Integrated Security=True"
Dim sourceconn As New SqlConnection(conn)
Dim adap As SqlDataAdapter
Dim cmd As SqlCommand = New SqlCommand("SELECT TOP(10) * FROM dbo.Prüf_Tabelle", sourceconn)
Dim Thrd_preview As Threading.Thread
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sourceconn.Open()
cmd.Connection = sourceconn
End Sub
Public Sub ReportProgress(ByVal Prozent As Double)
ProgressBar1.Value = Prozent
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RB_Thread.Checked Then
If Thrd_preview IsNot Nothing Then Thrd_preview = Nothing
Thrd_preview = New Threading.Thread(AddressOf DoSomeWork)
Thrd_preview.IsBackground = True
Thrd_preview.Start()
Else
DoSomeWork()
End If
End Sub
Private Sub DoSomeWork()
Dim ds As New DataSet
DT_G_Prüftabelle = ds.Tables.Add("Prüf_Tabelle")
Dim L_I_Counter, L_I_Counter2 As Integer
Dim L_I_Ende As Integer
Dim L_I_Step As Integer
Dim L_I_Nutzen As Integer = 1
L_I_Step = 1
L_I_Ende = Val(TB_Auftrag_neu_Anzahl.Text)
G_I_Stellen = 8
G_S_Prüfziffer = "1"
G_S_Präfix = "00"
If TB_Info_Increment.Text = "" Then TB_Info_Increment.Text = 1
adap = New SqlDataAdapter("SELECT TOP(10) * FROM dbo.Prüf_Tabelle", sourceconn)
adap.FillSchema(DT_G_Prüftabelle, SchemaType.Mapped)
DT_G_Prüftabelle.Rows.Clear()
Dim pre As Date = Now
For L_I_Counter = 1 To (L_I_Ende * L_I_Step) Step L_I_Step
For L_I_Counter2 = 1 To L_I_Nutzen
DR_G_Prüftabelle = DT_G_Prüftabelle.NewRow
DR_G_Prüftabelle.Item("Auftrag_Lfd_nr") = TB_KeyLot.Text
DR_G_Prüftabelle.Item("Position") = G_I_Position
G_I_Position += G_D_Step
DR_G_Prüftabelle.Item("Barcode_soll") = F_Berechnung((Trim(Str(Val(TB_Auftrag_neu_Von.Text) + L_I_Counter - 1))).PadLeft(G_I_Stellen, "0"))
DT_G_Prüftabelle.Rows.Add(DR_G_Prüftabelle)
If ProgressBar1.InvokeRequired Then
ProgressBar1.BeginInvoke(New ProzentDelegate(AddressOf ReportProgress), (L_I_Counter * 100) / (L_I_Ende * L_I_Step))
Else
ReportProgress((L_I_Counter * 100) / (L_I_Ende * L_I_Step))
End If
Next
Next
MsgBox(Now.Subtract(pre).TotalMilliseconds.ToString & " ms.")
End Sub
Function F_Berechnung(ByVal L_Nummer As String) As String
Dim L_B_Gerade As Boolean = False
Dim L_I_Prüfziffer As Integer
Dim L_I_Stellen As Integer
Me.G_I_Temp = 0
Select Case G_S_Prüfziffer
Case "0"
F_Berechnung = L_Nummer
Case "1"
F_Berechnung = G_S_Präfix & Trim(L_Nummer)
Case "2"
F_Berechnung = G_S_Präfix & Trim(L_Nummer)
Case "3"
F_Berechnung = L_Nummer
'
Case "5" '-----Mod 10 gewichtung 31...-----
L_Nummer = G_S_Präfix & Trim(L_Nummer)
L_I_Stellen = Len(L_Nummer)
For Me.G_I_Zähler = L_I_Stellen To 1 Step -1
Me.G_I_Temp += Val(Mid(L_Nummer, Me.G_I_Zähler, 1)) * IIf(L_B_Gerade, 1, 3)
L_B_Gerade = Not L_B_Gerade
Next
L_I_Prüfziffer = IIf(10 - Me.G_I_Temp Mod 10 = 10, 0, 10 - Me.G_I_Temp Mod 10)
F_Berechnung = Trim(L_Nummer) & Trim(Str(L_I_Prüfziffer))
'
Case "6" '-----Mod 10 gewichtung 13...-----
L_Nummer = G_S_Präfix & Trim(L_Nummer)
L_I_Stellen = Len(L_Nummer)
For Me.G_I_Zähler = L_I_Stellen To 1 Step -1
Me.G_I_Temp += Val(Mid(L_Nummer, Me.G_I_Zähler, 1)) * IIf(L_B_Gerade, 3, 1)
L_B_Gerade = Not L_B_Gerade
Next
L_I_Prüfziffer = IIf(10 - Me.G_I_Temp Mod 10 = 10, 0, 10 - Me.G_I_Temp Mod 10)
F_Berechnung = Trim(L_Nummer) & Trim(Str(L_I_Prüfziffer))
'
Case Else
F_Berechnung = L_Nummer
End Select
End Function
I have tried to take out Progress Reporting but the Result is the same.
I hope you have some suggestions or solutions for me. I would be very thankful.
Give these changes a try
Change this
If ProgressBar1.InvokeRequired Then
ProgressBar1.Invoke(New ProzentDelegate(AddressOf ReportProgress), Progr)
Else
ReportProgress(Progr)
End If
to
ReportProgress(Progr)
And change method ReportProgress to
Public Sub ReportProgress(ByVal Prozent As Double)
Me.BeginInvoke(Sub()
ProgressBar1.Value = Prozent
End Sub)
End Sub
See if that makes a difference. The check for InvokeRequired is not needed, the answer is always yes.
Just wanted to report that I found a solution.
The main problem was this line of code in:
DR_G_Prüftabelle.Item("Auftrag_Lfd_nr") = TB_KeyLot.Text
So if I start this Sub from another Thread rather than from a Main Thread, for every single loop it has to go to main thread and to take Paramater from TextBox and to go back in Thread to Loop further.
I took that out, declared a variable at the begining and assigned this TextBox value to it and it works like charm.
Also I took a suggestion from dbasnett to Invoke Reporting every time without If-Else and also the suggestion from Steven Doggart to Report every 100 Loops.
You guys helped a lot. Thanks for that!!

VB.NET IP disconnector: what is the correct usage of SetTcpEntry to disconnect

I am trying to create an IP disconnector. This is part from a template that I took that creates a TCPtable. I was trying to add a disconnecting function. However, it does not disconnect.
Dim liste() = {"76.9.24.130" ... ... ...}
Dim pdwSize As Integer
Dim iRetVal As Integer
Dim i As Integer
Dim TcpTableRow As MIB_TCPROW
Dim pStructPointer As IntPtr = IntPtr.Zero
Dim iNumberOfStructures As Integer
ListView1.Items.Clear()
iRetVal = GetTcpTable(pStructPointer, pdwSize, 0)
pStructPointer = Marshal.AllocHGlobal(pdwSize)
iRetVal = GetTcpTable(pStructPointer, pdwSize, 0)
iNumberOfStructures = Math.Ceiling((pdwSize - 4) / Marshal.SizeOf(GetType(MIB_TCPROW)))
For i = 0 To iNumberOfStructures - 1
Dim pStructPointerTemp As IntPtr = New IntPtr(pStructPointer.ToInt32() + 4 + (i * Marshal.SizeOf(GetType(MIB_TCPROW))))
TcpTableRow = New MIB_TCPROW()
With TcpTableRow
.dwLocalAddr = 0
.dwState = 0
.dwLocalPort = 0
.dwRemoteAddr = 0
.dwRemotePort = 0
End With
'Marshal.PtrToStructure(pStructPointerTemp, TcpTableRow)
TcpTableRow = CType(Marshal.PtrToStructure(pStructPointerTemp, GetType(MIB_TCPROW)), MIB_TCPROW)
' Process each MIB_TCPROW here
'If Not ((Check1.CheckState = System.Windows.Forms.CheckState.Checked) And (GetIpFromLong(TcpTableRow.dwLocalAddr) = "0.0.0.0" Or GetIpFromLong(TcpTableRow.dwLocalAddr) = "127.0.0.1")) Then
If Not GetIpFromLong(TcpTableRow.dwRemoteAddr) = "127.0.0.1" And Not GetIpFromLong(TcpTableRow.dwRemoteAddr) = "0.0.0.0" Then
'Add the data to the ListView control
With TcpTableRow
Dim itemAdd As ListViewItem
itemAdd = ListView1.Items.Add(GetIpFromLong(.dwLocalAddr))
itemAdd.SubItems.Add(CStr(GetTcpPortNumber(.dwLocalPort)))
itemAdd.SubItems.Add(GetIpFromLong(.dwRemoteAddr))
itemAdd.SubItems.Add(CStr(GetTcpPortNumber(.dwRemotePort)))
itemAdd.SubItems.Add(GetState(.dwState))
End With
'-------------- Kill Connection--------------
If Array.IndexOf(liste, GetIpFromLong(TcpTableRow.dwRemoteAddr)) >= 0 Then
TcpTableRow.dwState = 12
SetTcpEntry(TcpTableRow)
End If
End If
Next
I could not solve it but found an alternative solution using CurrPorts
Shell(Application.StartupPath & "\cports /close * * " & GetIpFromLong(TcpTableRow.dwRemoteAddr) & " " & GetTcpPortNumber(TcpTableRow.dwRemotePort))
I am not sure if this is the same situation or not but I was using:
session = New Socket(,,,) as my means of connecting via TCP PORT23 and my issue was that I too could not get the connection to close for some reason. I did try the CurrPorts workaround above but I found that did not meet my expectations. Instead I am using TCPClient.
Dim TCPConnection as TCPClient 'Init TCPConnect
Private Sub Connect(Byval inIP)
Dim PiP = IPAddress.Parse(inIP)
Dim iplocal As New System.Net.IPEndPoint(PiP, 23)
Try
TCPsession = New TcpClient
TCPsession.Client.Connect(ipLocal)
Catch
'On Error Do Nothing
End Try
End Sub
Private Sub Disconnect()
TCPsession.Client.Close()
End Sub
This code solved my issue but I am not sure if thats what you where even talking about.