c# - How to cure memory allocation issue on UI thread which is not an issue on command line? -


i have written algorithm (function) read in number of files list, manipulate , agglomerate files, , store single file. works fine , processes each file in under second , half.

to improve user experience created simple gui prep algorithm (input file list, output file location, , processing options etc.). works fine.

however, algorithm takes longer execute on ui thread (windows forms application), on command line thread (console application). can find no explanation why. command line execution time close linear number of files. ui thread or backgroundworker thread execution non-linear , becomes slow useful. see table below. (i killed 100 file run after 2 hours).

number of files 1, 3, 5, 13, 20
command line execution time 1s, 4s, 7s, 19s, 29s
ui backgroundworker execution time 1s, 7s, 22s, 309s, 441s

i thought backgroundworker class using perform processing, on removing backgroundworker , calling function directly button press caused slower (82 seconds 5 files (and caused ui lock)).

i have created standalone static test function, scattered stopwatches performance test , discover issue.

one thing highlighted getting slower , slower every additional file.

stopwatches[21].start(); byte[] candata = reader.readbytes(8); stopwatches[21].stop(); 

"reader" binaryreader. used both simple files, , ziparchiveentry files being processed.

other lines of code highlighted slowing, memory allocations, either "new" statement, or list<>.add functions.

my understanding of binaryreaders involves them buffering incoming information , therefore allocating memory. therefore believe memory issue. up, watching task manager ui thread/backgroundworker uses more memory command line version. suspect performance tails off in non-linear fashion because machine starts swapping.

what different memory allocation on ui (windows forms application) thread? , how should adapt code execute identically when run command line (console application)?

fault finding

after creating working ui fast command line (new trivial ui), started looking reasons application performing poorly, systematically removed code, call backs, methods, data, deleting components well, nothing helped. had 2 identical pieces of code, 1 working well, 1 not working... systematically did diff of files in each project folder, tried understand important differences (ignore names changes etc.), found thought issue. altered file outside of visual studio, rebuilt , ran... , performance good. success, fault found.

the answer

the fault in csproj file.

<reference include="system.core">   <requiredtargetframework>3.5</requiredtargetframework> </reference> <reference include="system.net.http" /> <reference include="system.xml.linq">   <requiredtargetframework>3.5</requiredtargetframework> </reference> <reference include="system.data.datasetextensions">   <requiredtargetframework>3.5</requiredtargetframework> </reference> 

which modified following

<reference include="system.core" /> <reference include="system.net.http" /> <reference include="system.xml.linq" /> <reference include="system.data.datasetextensions" /> 

note both had

<targetframeworkversion>v4.5</targetframeworkversion> 

also: still can't find in visual studio option set, did go through both sets of properties before looking in files check, after finding issue it's still hidden me in visual studio.

i believe because copied form form upgraded visual studio 2008, , upgrade process must have completed incorrectly. upgraded using visual studio 2015.

one watch for... quick last question. should update title (main question) better articulate actual problem?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -