c# - how to improve the performance of streamwriter -
i'm working on smart device compact framework 3.0 i'm using streamwriter class write data on file. file size 256kb it's taking 60 seconds save file.
here code:
using (streamwriter sw = new streamwriter(tmppath, true)) { sw.autoflush = true; sw.writeline(_rm.getstring("key")); sw.writeline(rm.getstring("key1") + "\t" + controller.time.tostring("yyyy-mm-ddhh:mm:ss")); sw.writeline(rm.getstring("name") + "\t" + controller.systemname); sw.writeline(rm.getstring("systemname") + "\t" + stctrlname); sw.writeline(rm.getstring("systemid") + "\t" + stctrlid); sw.writeline(); controller.getversion(out major, out minor, out revision, out build); sw.writeline(rm.getstring("build") + string.format("\t{0}.{1}.{2}", major, minor, build)); sw.writeline(optionssection(systeminfo.moduletype.control)); sw.writeline(); sw.writeline(optionssection(systeminfo.moduletype.drive)); sw.writeline(); sw.writeline(optionssection1()); string header = formatmsg(stseqno, sttype, stdomain, stid, sttitle, stdate, rm.getstring("key2"), stargs); using (log evlog = new log(log.domaintype.all)) { sw.writeline(); // {0} log messages string domain = string.format(rm.getstring("stbevt_txt_logfilenewdomain"), log.geteventlogdescription(log.domaintype.all)); sw.writeline(domain); // write column headings sw.writeline(header); string str = string.empty; foreach (eventmessage em in evlog.getevents()) { sw.writeline(formatmsg(em.sequencenumber, em)); } } log.domaintype domtype = log.domaintype.noofdomains; foreach (eventmessage em in allevents) { if (_progressbar._pbar.value >= _progressbar._pbar.maximum) { _progressbar._pbar.value = 0; } else { _progressbar._pbar.value += 1; } if (em.domain != domtype) { sw.writeline(); // {0} log messages string domain = string.format(rm.getstring("stbevt_txt_logfilenewdomain"), log.getlogdescription(em.domain)); sw.writeline(domain); // write column headings sw.writeline(header); domtype = em.domain; } sw.writeline(formatmsg(em.sequencenumber, em)); }
please tell me how can improve performance such take 10 15seconds save 256kb data.
Comments
Post a Comment