vb.net - Form crashes when uploading file on background thread -
vb.net - Form crashes when uploading file on background thread -
i trying upload file using thread. have placed simple file upload command , button on page.the code looks this-
protected sub btnupload_click(byval sender object, byval e eventargs) handles btnupload.click dim timestart timespan = nil dim timeend timespan = nil dim timediff timespan = nil dim ex exception = nil dim filenamewithoutextension string = string.empty seek dim objth thread = nil objth = new thread(addressof savefilebybuffering) timestart = datetime.now.timeofday objth.isbackground = true filenamewithoutextension = system.io.path.getfilename(flduploadthreading.filename) objth.start("new_" + filenamewithoutextension) objth.name = "arathreadfilebuffer" objth.join() timeend = datetime.now.timeofday timediff = timeend - timestart grab exthabort threadabortexception ex = exthabort grab exth threadstartexception ex = exth grab excommon exception ex = excommon end seek end sub
method called using thread:
public function savefilebybuffering(byval lstrfilepath string) dim buffersize integer = 512 dim buffer byte() = new byte(buffersize - 1) {} dim pathurl string = configurationmanager.appsettings("strfilepath").tostring() dim uploadobj uploaddetail = new uploaddetail() uploadobj.isready = true uploadobj.filename = lstrfilepath uploadobj.contentlength = me.flduploadthreading.postedfile.contentlength me.session("uploadxdetail") = uploadobj dim upload uploaddetail = directcast(me.session("uploadxdetail"), uploaddetail) dim filename string = path.getfilename(me.flduploadthreading.postedfile.filename) using fs new filestream(path.combine(pathurl, lstrfilepath), filemode.create) while upload.uploadedlength < upload.contentlength dim bytes integer = me.flduploadthreading.postedfile.inputstream.read(buffer, 0, buffersize) fs.write(buffer, 0, bytes) upload.uploadedlength += bytes end while end using end function
there 2 issues:
when clicks on same button simultaneously thread behavior works in different way, time page crashes.
when process have tested on multi-user environment 60 users , file size 25 mb each user page crashed.
i have utilize .net 3.5 cannot utilize advanced version of file upload in 2010 or later.
error : 1-file uploding more 15 minutes still in progress 2- net explorer cannot explore page -diagnose net problems 3- user login probem server on site has hosted
the course of study take in .net utilize threadpool.queueuserworkitem
if anonymous lambdas, find makes syntax , life rather nice. can this:
btnupload.enabled = false threadpool.queueuserworkitem(sub() savefilebybuffering(flduploadthreading.filename) raiseevent enablebutton end sub)
with event handler:
public sub enablebutton() handles enablebutton if me.invokerequired me.begininvoke(sub() enablebutton()) else btnupload.enabled = true endif endsub
my .net rusty , don't have compiler anywhere, doing should handle of issues.
vb.net multithreading
Comments
Post a Comment