Results 1 to 6 of 6

Thread: Background Worker Headaches

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    26

    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

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: Background Worker Headaches

    What are you spamming?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    26

    Re: Background Worker Headaches

    Quote Originally Posted by dbasnett View Post
    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.

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    26

    Re: Background Worker Headaches

    Quote Originally Posted by Sitten Spynne View Post
    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.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    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
  •  



Click Here to Expand Forum to Full Width