I am now working with background worker and I've optimized all of my code and fixed a lot of things.
New MainThread Method
Code:
Sub Background_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackGround.DoWork
While (Not BackGround.CancellationPending) AndAlso (isRunning)
RunCodeWith(e.Argument(0), e.Argument(1))
End While
End Sub
Sub RunCodeWith(ByRef Lines As String(), ByVal isChecked As Boolean)
If Lines.Count > 0 And isRunning Then
For Each strLine As String In Lines
arr = {}
arr = strLine.Split(Space)
Select Case arr(Zero)
Case ClickCmd
Try
If isChecked Then
Select Case RND.Next(Zero, Five) 'Now the range is 0-4, it was 0-3 previously
Case Zero : Windows.Forms.Cursor.Position = New Point(arr(One) + One, arr(Two))
Case One : Windows.Forms.Cursor.Position = New Point(arr(One) - One, arr(Two))
Case Two : Windows.Forms.Cursor.Position = New Point(arr(One), arr(Two) + One)
Case Three : Windows.Forms.Cursor.Position = New Point(arr(One), arr(Two) - One)
Case Four : Windows.Forms.Cursor.Position = New Point(arr(One), arr(Two))
Case Else : Console.WriteLine("Unhandled BriefCase...")
End Select
Else
Windows.Forms.Cursor.Position = New Point(arr(One), arr(Two))
End If
mouse_event(LEFTDOWN, Zero, Zero, Zero, One)
Delay(RND.Next(Zero, arr(Three)))
mouse_event(LEFTUP, Zero, Zero, Zero, One)
Delay(RND.Next(Zero, arr(Four)))
Catch ex As Exception
End Try
Case EndCmd : isRunning = False : CancelWork()
Case Else : Console.WriteLine("Wh8 whut...")
End Select
Next
Else
CancelWork()
End If
End Sub
Old MainThread Method
Code:
Public Sub RunCode()
While isRunning = True
For Each strLine As String In RichTextBox1.Lines
Dim arr() As String = strLine.Split(" ")
Select Case arr(0)
Case "CLICK"
Try
If CheckBox1.Checked = True Then
DirVar = RND.Next(0, 4)
If DirVar = 0 Then
Windows.Forms.Cursor.Position = New Point(arr(1) + 1, arr(2))
ElseIf DirVar = 1 Then
Windows.Forms.Cursor.Position = New Point(arr(1) - 1, arr(2))
ElseIf DirVar = 2 Then
Windows.Forms.Cursor.Position = New Point(arr(1), arr(2) + 1)
ElseIf DirVar = 3 Then
Windows.Forms.Cursor.Position = New Point(arr(1), arr(2) - 1)
ElseIf DirVar = 4 Then
Windows.Forms.Cursor.Position = New Point(arr(1), arr(2))
End If
Else
Windows.Forms.Cursor.Position = New Point(arr(1), arr(2))
End If
mouse_event(LEFTDOWN, 0, 0, 0, 1)
Delay((RND.Next(arr(3))) / 1000)
mouse_event(LEFTUP, 0, 0, 0, 1)
Delay((RND.Next(arr(5))) / 1000)
Catch ex As Exception
End Try
Case "END"
isRunning = False
End Select
arr = Nothing
Next
End While
End Sub
Basically throughout my entire code I've fixed things up, and optimized what I can like the click listbox Mouse Coordinates to Textbox feature
Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim word As String = ListBox1.SelectedItem.ToString
Dim wordArr As String() = word.Split(",")
Dim result As String = wordArr(1)
Dim Result2 As String = wordArr(0)
TextBox1.Text = Result2
TextBox2.Text = result
End Sub
Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim wordArr As String() = ListBox1.SelectedItem.ToString.Split(",") 'Dim word As String = ListBox1.SelectedItem.ToString
TextBox1.Text = wordArr(0) ' Dim Result2 As String = wordArr(0)
TextBox2.Text = wordArr(1) ' Dim result As String = wordArr(1)
End Sub
I also got rid of my timers which were also causing lag. With all of my optimizations and running it through BGW I've managed to keep the script from "Lagging" to the point that you may miss a turn during battle. I have not ran this all night using this new method so I'm not too sure how well it wil work but from what I've done so far it seems to work great. It also shouldn't stay running in the Task manager, it will all properly be handled now so the thread shuts down with the application.
Screenshot
Scans
https://virusscan.jotti.org/ru/scanre...cdac16ad31cf76
https://www.virustotal.com/en/file/c...is/1408373235/
Increase a click delay to about 10000 to avoid "freezing"(unable to use mouse), if you run the program for a long time it eventually the SWF will cause the thread to back up and it will be forced to complete what is hasn't already and what its being told to do next. So when this happens the only way to stop it is to disconnect your connection so your SWF shuts off allowing the thread to sync so you can shut the program off, or whatever you want to do.