vb.net - Trying To Create A Small Mail App - Getting Lag When Checking For Mail And Typing New Message -
in application working on, have built functionality allows users send 'mini' emails each other. basically, output contents mysql db, , poll db check if there entries db user read=false status. have form shows inbox (and outbox) of messages refreshes when open. problem finding when user types detail message body field, there constant lag every xx when software checks db new messages.
i know haven't set correctly , i'm therefore after best method of building routine.
mainform: has timer fires every 5 seconds runs query against db , returns integer value select count(*) mail is_read = 0 , recipient = " & current_user.id
showmessagesform: when opened, makes initial query db , returns messages current user datatable. clears listview control , re-populates using datatable.
private sub loadmessages() dim querystring string try 'populate inbox lsvmail.items.clear() if inboxdatatable isnot nothing inboxdatatable.clear() querystring = "select m.id, recipient.display_name recipient, sender.display_name sender, m.subject, m.body, m.call_id, m.is_read, m.replied, m.followup, m.deleted, m.sent_deleted, m.sent " & _ "from mail m " & _ "left join clients sender on m.sender = sender.id " & _ "left join clients recipient on m.recipient = recipient.id " & _ "where m.recipient = " & current_user.id & " , m.deleted = 0 " & _ "order m.sent desc" inboxdatatable = db_connection.returndata(querystring) if inboxdatatable.rows.count > 0 x = 0 (inboxdatatable.rows.count - 1) dim lvi new listviewitem(inboxdatatable.rows(x)("replied").tostring) lvi.subitems.add(inboxdatatable.rows(x)("sender").tostring) if cbool(inboxdatatable.rows(x)("is_read")) = true lvi.font = regularfont else lvi.font = boldfont end if if cbool(inboxdatatable.rows(x)("followup")) = true lvi.forecolor = color.red else lvi.forecolor = color.black end if lvi.subitems.add(decryptdata(inboxdatatable.rows(x)("subject").tostring)) lvi.subitems.add(inboxdatatable.rows(x)("sent").tostring) lvi.subitems.add(inboxdatatable.rows(x)("followup").tostring) lvi.name = inboxdatatable.rows(x)("id").tostring lsvmail.items.add(lvi) next end if catch ex exception createlog("module: frmshowmessages: loadmailmessages()" & vbnewline & "exception error: " & ex.message) msgbox("exception error: " & ex.message, msgboxstyle.critical, "module: frmshowmessages: loadmailmessages()") end try end sub
there timer control on form fires every 5 seconds runs above sub routine everytime.
composemessageform: contains subject textbox , body richtextbox control.
when enter text richtextbox, finding everytime timer triggers on showmessagesform, creates lag in typing on form.
so basically, guess asking best method of creating small application checks messages? needs check on main form see if user has new messages, , refresh inbox listview in case messages arrive whilst form open.
thanks in advance.
you must use multiple threads such case. way polling logic implemented in separate thread , not affect rest of application.
Comments
Post a Comment