Not sure but I will try with Using picture = TakeImage(), also remove all that path concatenation and use Path.Combine. Last, there is a problem with your j variable. You send img+i but delete img+j
–
SteveAug 8 '13 at 12:37

Yeah Because I want to make 3 picture in folder name "pic" but I cant rewrite it as the error "generic gdi+" will occur so I need to delete the pictures then save as new image.
–
EmPlusPlusAug 8 '13 at 12:44

1 Answer
1

You should first set Option Strict ON, then fix the warnings and errors that will be shown and then edit your post to the actual code.

The cause of the exception is a timing problem between the tmrEmail Timer object and the tmrScrShot Timer object.

EDIT:

This method takes a Image object which is then saved to a memory stream which is used to create a System.Net.Mail.Attachment

Private Function ToAttachment(img As Image) As System.Net.Mail.Attachment
Dim attachment As System.Net.Mail.Attachment
Using ms As New System.IO.MemoryStream()
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
attachment = New System.Net.Mail.Attachment(New System.IO.MemoryStream(ms.GetBuffer), "image.png", "image/png")
End Using
Return attachment
End Function

I have already fixed the timing problem I think because tmrEmail.interval = 60000 and tmrScrShot.interval = 19000 is it ok?
–
EmPlusPlusAug 8 '13 at 13:01

You also need to take care of the time which is needed to save the image. So if saving takes 1 second and some milliseconds the last saving ( the third pic ) could take place at the time you want to add the image as attachment.
–
HeslacherAug 8 '13 at 13:08

so is there any way that I can use instead of deleting the file ? because for rewriting the generic gdi+ error will occur!
–
EmPlusPlusAug 8 '13 at 13:12

How about avoiding the saving to a file and instead save it to a memory stream ?
–
HeslacherAug 8 '13 at 13:18

Just have seen how you are sending the images.You create a MailMessage and then you do the for loop. Inside the for loop you add the first image to the message and send the message. Then you add the second image (now the message contains 2 images) and you send it again then on the last iteration you add the third image to the message which results in a message with 3 images which is sent. As a tip: redesign your application.
–
HeslacherAug 8 '13 at 13:22