branching off previous question... retrieving print command sql server procedure in vb.net
i able dump text sql server's messages , use need reason unable update textbox events.
private shared sub oninfomessage(byval sender object, byval e system.data.sqlclient.sqlinfomessageeventargs) dim counter integer counter = 1 each line in e.message.split(vbnewline) if (line.contains("====")) restoretool.txttrnstatus.text = "trn #" & counter & "restored" using logfile io.streamwriter = new io.streamwriter("c:\sdbt\worklog.ft", true) logfile.writeline(line) end using counter += 1 end if next everything runs smoothly textbox (txttrnstatus) not update , remains blank (where should showing "trn #1 restored")
i utilizing background worker call procedure performs restoration of database. procedure contains event handler sqlinfomessages.
dim sql sqlcommand dim dbconn new sqlconnection(connectionstring) sql = new sqlcommand(dbscript, dbconn) addhandler dbconn.infomessage, new sqlinfomessageeventhandler(addressof oninfomessage) dim sqlresult iasyncresult = sql.beginexecutenonquery() try catch e exception messagebox.show(e.message) end try sql.endexecutenonquery(sqlresult) completedtask = true dbconn.close() i have feeling way can text update through addition of in dowork() portion of backgroundworker cannot figure out exactly. can oninfomessages called @ when update needed or specific event handler is?

as can see in image, it's during actual "restoration" tool report transaction log has been restored based off of sql message received remains blank...
thank once again!
edit: progress update background worker set correctly, having trouble calling events oninfomessage sub progress update gets next line sql.
make sure use backgroundworker properly. in "dowork" there must not have line of code affect ui(userinterface) thread isn't main thread of application. if does, either crash or nothing.
so if need change ui background worker need tell main thread "dowork" method. can achieved hooking callback event "progresschanged" of backgroundworker object.
' event handler updates ui. ' private sub backgroundworker1_progresschanged( _ byval sender object, byval e progresschangedeventargs) _ handles backgroundworker1.progresschanged me.txttrnstatus.text = e.userstate.tostring()//update ui end sub from "dowork" method, raise event shown below tell main thread update ui. use second parameter pass whatever needed main thread so.
private sub backgroundworker1_dowork(sender object, e doworkeventargs) ' method run on thread other ui thread. ' ' sure not manipulate windows forms controls created' ' on ui thread method.' dim someobject [object] //some stuff backgroundworker.reportprogress(1, someobject) //some stuff backgroundworker.reportprogress(2, someobject) end sub see msdn more detail on backgroundworker usage.
or use "invoke" @mark suggested in comment. tell main thread execute sub. long ui update done main thread fine.
Comments
Post a Comment