我试图使用this great project但由于我需要扫描许多映像,因此我需要花费很多时间来处理多线程。
但是,由于使图像实际处理的类使用Static methods
并且正在操作Objects
ref
我不确定如何正确执行此操作。我从我的主线程中调用方法是:从C#中的线程调用静态方法
public static void ScanPage(ref System.Collections.ArrayList CodesRead, Bitmap bmp, int numscans, ScanDirection direction, BarcodeType types)
{
//added only the signature, actual class has over 1000 rows
//inside this function there are calls to other
//static functions that makes some image processing
}
我的问题是,如果它的安全使用,使用此功能是这样的:
List<string> filePaths = new List<string>();
Parallel.For(0, filePaths.Count, a =>
{
ArrayList al = new ArrayList();
BarcodeImaging.ScanPage(ref al, ...);
});
我已经花了几个小时的调试,并大部分时间我得到的结果是正确的,但我确实遇到了几个我现在无法重现的错误。
编辑
我粘贴类的代码在这里:http://pastebin.com/UeE6qBHx
没有分析方法本身没人能告诉你它是否是线程安全的! – Yahia
“伟大的项目”仍使用过时的ArrayList类,这让我担心它的线程安全性。 –
如果它使用全局变量(或者变量没有用作参数或函数内部),那么它是一个否定的。 –