Monday 15 February 2010

c# - System.OutOfMemoryException while after execution for an hour -



c# - System.OutOfMemoryException while after execution for an hour -

why got "system.outofmemoryexception"

this code provide service read smart card smart card reader , set result in textbox focus in application. while running (more 60 minutes) got error throw out. happen in case?

please advice

class programme { static bool infinity = true; static winscard scard; public static void main(string[] args) { seek { scard = new winscard(); while (infinity) { scard.establishcontext(); //establis smart card reader resourete manager scard.listreaders(); //get list of smart card reader string readername = scard.readernames[0]; //the first smart card reader in list scard.waitforcardpresent(readername); //block execution until smart card attached reader scard.connect(readername); //connect smart card // console.writeline( "atr: 0x" + scard.atrstring ); byte[] cmdapdu = { 0xff, 0xca, 0x00, 0x00, 00 }; // card uid ... byte[] respapdu = new byte[6]; int resplength = respapdu.length; //submit command smart card , homecoming result scard.transmit(cmdapdu, cmdapdu.length, respapdu, ref resplength); //convert bute[] hexstring , integer int num = int32.parse(bytearraytostring(respapdu, resplength), system.globalization.numberstyles.hexnumber); console.writeline("get card uid ==> " + num); //send result input got focus sendkeys.sendwait(num.tostring()); scard.waitforcardremoval(readername); //block execution until smart card removed reader scard.disconnect(); //terminated connection smart card scard.releasecontext(); //freely resource allocated under context } } grab (winscardexception ex) { console.writeline( ex.winscardfunctionname + " 0x" + ex.status.tostring( "x08" ) + " " + ex.message ); } { console.writeline("please press key..."); console.readline(); } } public static string bytearraytostring(byte[] ba, int length) { stringbuilder hex = new stringbuilder(length * 2); foreach (byte b in ba) hex.appendformat("{0:x2}", b); homecoming hex.tostring().replace("9000",""); } }

are there classes in code implement idisposable , not disposing them, or pinvoke calls, need additional calls cleanup memory allocated them.

c# c#-4.0

No comments:

Post a Comment