-
Oct 22nd, 2017, 08:33 AM
#1
Thread Starter
Junior Member
Background Worker Headaches
I'll start by saying, I am a total noob when it comes to programming (as will become evident when you see my code).
I started messing about with timers and made a spam bot using timers with sendkeys. All was going well until my GUI started freezing when the program was running. Someone suggested BackgroundWorkers and I decided to dip my toe in a little further and maybe learn something new in the process. The result of my endeavours was my code getting pretty messed up by trying to implement the worker.
Now, all that happens is it spams in its own text fields (last clicked) and the worker doesn't seem to be working as intended (apart from the messagebox in RunWorkerCompleted).
Code:
Imports System.ComponentModel
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
Timer1.Interval = 2000
Timer1.Enabled = True
txtCounter.Text = "0"
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
Timer1.Enabled = False
BackgroundWorker1.CancelAsync()
BackgroundWorker1.Dispose()
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtSpam.Text = ""
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim int As Integer
int = txtInt.Text * 1000
If txtLimit.Text = "None" Then
txtLimit.Text = 300
Else
txtLimit.Text = txtLimit.Text
End If
End Sub
Private Sub CarbonFiberButton1_Click(sender As Object, e As EventArgs) Handles CarbonFiberButton1.Click
Me.Close()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Do While Val(Trim(txtCounter.Text)) <= Val(Trim(txtLimit.Text - 1))
Dim int As Integer
int = txtInt.Text * 1000
SendKeys.SendWait(txtSpam.Text)
SendKeys.SendWait("{Enter}")
txtCounter.Text = txtCounter.Text + 1
Threading.Thread.Sleep(int)
Loop
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MessageBox.Show("Spam limit has been reached.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
-
Oct 22nd, 2017, 09:44 AM
#2
Re: Background Worker Headaches
-
Oct 22nd, 2017, 09:46 AM
#3
Thread Starter
Junior Member
Re: Background Worker Headaches
Originally Posted by dbasnett
What are you spamming?
Nothing really, just a tool I am making for fun and practice. Nothing in mind. Was testing it on Facebook messages and Discord.
-
Oct 22nd, 2017, 10:31 AM
#4
Re: Background Worker Headaches
There are good reasons it is not working, but I'm afraid I don't directly answer questions about programs that do things like this.
That said, practically anything I've ever written about BackgroundWorker, or any tutorial about using it with UI, should have a giant flashing sign that says not to do something you are doing. If you find that on your own, well, I can't stop you.
But it's probably best to go explore a program that doesn't do something annoying, then we'd just spit out the answer.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Oct 22nd, 2017, 01:44 PM
#5
Thread Starter
Junior Member
Re: Background Worker Headaches
Originally Posted by Sitten Spynne
There are good reasons it is not working, but I'm afraid I don't directly answer questions about programs that do things like this.
That said, practically anything I've ever written about BackgroundWorker, or any tutorial about using it with UI, should have a giant flashing sign that says not to do something you are doing. If you find that on your own, well, I can't stop you.
But it's probably best to go explore a program that doesn't do something annoying, then we'd just spit out the answer.
I know what you mean but this was made solely for my own learning and not to annoy people. I have fixed it, thankfully but now my stop button isn't working. Hopefully I can sort that out too. Despite it being strictly educational, I wouldn't want to leave it unfinished.
-
Oct 22nd, 2017, 03:50 PM
#6
Re: Background Worker Headaches
It doesn't matter whether you were doing this to be malicious, or just so that you'd have the option later. We don't condone the behavior, or asking questions about it. Therefore, this thread is closed.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|