Android Question NET/SMTP triggering the MessageSent event

Discussion in 'Android Questions' started by SeaCay, Jun 10, 2015.

  1. SeaCay

    SeaCay Member Licensed User

    Hello All,

    One of my apps needs to send several emails at end of app, usually 2 to 5. I am using the NET library, SMTP component to handle the sending of emails.
    I have a list of emails I need to send and wanted to loop through the list, sending one email at a time while waiting for the MessageSent event to trigger. The MessageSent resets a flag to tell the loop, that it is Ok to process the next message.

    However, through testing (with a whole lot of debugging code), it seems that the MessageSent trigger only fires when the loop is ended for all iterations (or possibly when the app is inactive). When the loop has exhausted all its iterations, the MessageSent trigger is fired consecutively for the number of file sent.


    The loop code looks like
    Code:
    For kount = 0 To emailsMap.Size-1
                    
    If emailsMap.GetValueAt(kount) = True Then
                        resendFile(emailsMap.GetKeyAt(kount))
                        timeKount = 
    0
                        
    Do While (okForNext = False)   ' flag set to false by the previous call to resendFile
                            ESCommon.Sleep(1000)   ' Sleep for a second
                        Loop
                    
    End If
                
    Next
    The resend procedure sends the SMTP request and sets the okForNext flag to false.

    Is there any way to have the MessageSent trigger fire in the middle of the loop? That is the MessageSent firing can take a higher precedence that the loop and temporarily interrupt the the loop to process the MessageSent code?

    regards and many thanks

    SeaCay
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    No. You should never try to hold the main thread. It will not work.

    Instead continue the program flow from the event.
     
  3. SeaCay

    SeaCay Member Licensed User

    Thanks Erel,
    I had a suspicion that that might be the case.
    Thanks for your suggestion.
    regards
    SeaCay
     
Loading...