vb.net - How to load items from text file into listbox using multiple thread -


i'm using following code load text file items listbox in 1 of application , works size of text file more 10mb. application stuck few seconds @ time of loading items listbox.

once item loaded works fine. there way reduce loading time , prevent application hanging.

public sub loadfiles()     dim systemdrv string = mid(environment.getfolderpath(environment.specialfolder.system), 1, 3)     dim r io.streamreader     r = new io.streamreader(systemdrv + "temp\test.txt")     while (r.peek() > -1)         listbox2.items.add(r.readline)     end while     r.close() end sub 

i read using multiple threads can solve problem. try few thing failed every time...

multiple reading single file aren't solution, in cases won't reduce in loading time since access storage de facto sequential. can prevent application hanging wrapping in backgroundworker or in action.

beware in windows form main thread has created form can modify component in form, need store result in additional variable or wrapping every modify action in delegate. if want maintain loading effect (useful give working effect client) can wrap in backgroundworker using delegate.

private sub backgroundworker1_dowork(byval sender system.object, byval e system.componentmodel.doworkeventargs) handles backgroundworker1.dowork     dim systemdrv string = mid(environment.getfolderpath(environment.specialfolder.system), 1, 3)     dim r io.streamreader     r = new io.streamreader(systemdrv + "temp\test.txt")     while (r.peek() > -1)         dim line string = r.readline         if listbox2.invokerequired             listbox2.invoke(sub() listbox2.items.add(line))         else             listbox2.items.add(line)     end while     r.close() end sub 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -