multithreading - Invoking static methods from thread in C# -
i'm trying use this great project since need scan many images process takes lot of time thinking multi-threading it.
however, since class makes actual processing of images uses static methods
, manipulating objects
ref
i'm not sure how right. method call main thread is:
public static void scanpage(ref system.collections.arraylist codesread, bitmap bmp, int numscans, scandirection direction, barcodetype types) { //added signature, actual class has on 1000 rows //inside function there calls other //static functions makes image processing }
my question if it's safe use use function this:
list<string> filepaths = new list<string>(); parallel.for(0, filepaths.count, => { arraylist al = new arraylist(); barcodeimaging.scanpage(ref al, ...); });
i've spent hours debugging , of time results got correct did encounter several errors can't seem reproduce.
edit
pasted code of class here: http://pastebin.com/uee6qbhx
there's no way of telling unless know if stores values in local variables or in field (in static class, not method).
all local variables fine , instanced per call, fields not.
a bad example:
public static class testclass { public static double data; public static string stringdata = ""; // can, , quite often, return wrong values. // example returning result of f(8) instead of f(5) // if data changed before stringdata calculated. public static string changestaticvariables(int x) { data = math.sqrt(x) + math.sqrt(x); stringdata = data.tostring("0.000"); return stringdata; } // won't return wrong values, variables // can't changed other threads. public static string nonstaticvariables(int x) { var tdata = math.sqrt(x) + math.sqrt(x); return data.tostring("0.000"); } }
Comments
Post a Comment