[VB.Net]

Discussion in 'Mixed Languages' started by ryuuichie, May 24, 2013.

  1. ryuuichie

    ryuuichie MDL Novice

    Jan 25, 2013
    22
    0
    0
    Hey guys. I am currently making a program that send email (thru SMTP) and I'm halfway done with it.
    But, I wanted to add multi-threading to it so that when the program is in the process of sending the email, the program is still responsive.

    I did attempt multi-threading but, yea, I failed. No errors were found but it won't just do what I want it to do. The program is still unresponsive.


    My question may sound noobish to people out there, but I'm just a beginner at this thing. Hope you understand :tea:
     
  2. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    the easiest way is just to use a background worker from the tools section in the gui builder, then do your send mail code in there, you could actually program another thread but for your purposes i think background worker is the easiest
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #3 QuantumBug, May 24, 2013
    Last edited by a moderator: Apr 20, 2017
    Directives
    Code:
    Imports System.Threading
    
    Declarations
    Code:
    Private eThread as Thread
    
    Email send method
    Code:
    Private Sub SendMail()
    
    'Your code to send the email here plus applicable cross thread handling.
    'For example If (Label1.InvokeRequired) Then/Else/End If, or
    'adding a Private Delegate Sub to update controls.
    
    End Sub
    
    Usage
    Code:
    eThread = New Thread(AddressOf SendMail)
    eThread.IsBackground = True
    eThread.Start
    
    This should get you started. If you need any more help feel free to ask. The last threading you did may have failed due to unhandled cross-thread calls.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    418
    60
    I think The Dev can help you with it. I know he knows how to do cross thread stuff the right way :p If you have anything else just ask me also. I love VB.NET :cool:
     
  5. ryuuichie

    ryuuichie MDL Novice

    Jan 25, 2013
    22
    0
    0
    What did I do wrong?

    help.jpg
     
  6. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,460
    418
    60
    The Timer.Stop() needs to be Invoked in order for it to function properly - Also create Private Shared global variables to be on the safe side of things - The way you have it now it does a cross thread call to get the information in your text boxes.
     
  7. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #7 QuantumBug, May 24, 2013
    Last edited by a moderator: Apr 20, 2017
    What is the Timer for? Also, you need to invoke the text in the textboxes.

    Is it throwing any error?

    You may also need to add this to Form2...
    Code:
    Public Shared t1 As String ' // TextBox1 data
    Public Shared t2 As String ' // TextBox2 data
    These will be allocated for TextBox1.Text and TextBox2.Text to globally share information across forms.

    If you want me to look at your code, you can send it over to me.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. ryuuichie

    ryuuichie MDL Novice

    Jan 25, 2013
    22
    0
    0
  9. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,292
    60
    #9 QuantumBug, May 25, 2013
    Last edited: May 25, 2013
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...