c# - Createhardlink in managed code -
i'm developing application creates hundreds of thousands of hardlinks (this core feature of application).
i use parallel programming features available in dotnet 4.0. works well. see example snippits below.
either:
parallel.for(from, until, delegate(int i) { j += 1; fileindex = convert.toint32(math.round(j * 0.001) + 1); //determine hardlink files; have have unique name hardlink each individual hardlink filename = fiarray[fileindex].name; //path.getfilenamewithoutextension(textboxfile.text); destinationfilename = path.combine(textboxdestination.text, string.concat(filename, "_", i.tostring(), ".txt")); fr.createhardlink(destinationfilename, fiarray[fileindex].fullname); });
or:
//loop actual work (int = 0; < nudthreads.value; i++) { //determine work package per task = 0 + until + 1; until = (i * (convert.toint32(hardlinks / threadno))) + 1; var compute = task.factory.startnew(() => { token.throwifcancellationrequested(); //uit boek return work(from, until, false);//todo: counter moet nog worden meegenomen }, tokensource.token); tasks.add(compute); var displayresults = compute.continuewith(resulttask => updatecontrols(), cancellationtoken.none, taskcontinuationoptions.onlyonrantocompletion, ui); checkedlistboxfiles.items.add(datetime.now.tostring() + " : created hardlinks for: " + displayresults + " files."); application.doevents(); var displaycancelledtasks = compute.continuewith(resulttask => updatecontrols(), cancellationtoken.none, taskcontinuationoptions.onlyoncanceled, ui); checkedlistboxfiles.items.add(datetime.now.tostring() + " : cancelled task at: " + displaycancelledtasks + " files."); application.doevents(); }
the question have this: createhardlink part of kernel32.dll , hence runs in unmanaged code. know parallel ctp parallel tasks have run in managed code. there managed alternative createhardlink? know how create hardlink in managed code , have thougths parallel programming , using unmanaged code?
there's little point in trying create hard links in parallel fashion. not cpu bound operation, i/o bound. not expect performance benefit approach when compared against naive serial approach.
your question managed , unmanaged code relating hardlink creation interesting. must remember i/o access managed code @ point call unmanaged code. os not managed , way create hardlink go through os. think need more precise restriction of ctp managed code means.
Comments
Post a Comment