如题,这个问题本人已经纠结了快三个工作日了。本人不同WinFrom程序一起动就会开启10个线程,并发对10张图片进行算法处理,问题是只要程序一起动就会报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”异常。

本人试过将8个线程停掉,只开两个,发现没有问题,开三个四个偶尔会出问题….反正10个一个开是一定会报异常的。开起来好像是线程开太多CPU反应不过来导致的问题,可是CPU反应不过来就会报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”异常吗?本人在网上查了查这种多线程并发报异常的问题很可能是线程与线程间有共享资源导致的问题,本人倒觉得没有共享什么资源啊,各位高手帮本人看看本人的线程处理函数里面存在共享资源吗?

线程1的线程处理函数:

private void AlgorithmHandlerThreadMethod1()

{

Bitmap test1 = new Bitmap("E:\和路雪\和路雪 2014-7-09\TestControl\蛋筒\1.jpg");

ProjectCalculation testHalcon = new ProjectCalculation();

ConesInspectionHalcon01 ParameterIn = new ConesInspectionHalcon01();

ConesInspectionHalcon01 ParameterOut = new ConesInspectionHalcon01();

ParameterIn.AreaAddSet = 50000;

ParameterIn.MaxAreaSet = 350;

ParameterIn.MaxEdgeSet = 150;

ParameterIn.AreaCutSet = 40000;

while (true)

{

if (threadFlag)

{

long start = DateTime.Now.Ticks;

ProjectCalculation.ConesInspectionHalcon01(test1, ParameterIn, out ParameterOut);

Thread.Sleep(1000);

}

}

}

线程2的线程处理函数:

private void AlgorithmHandlerThreadMethod2()

{

Bitmap test2 = new Bitmap("E:\和路雪\和路雪 2014-7-09\TestControl\蛋筒\2.jpg");

ProjectCalculation testHalcon = new ProjectCalculation();

ConesInspectionHalcon01 ParameterIn = new ConesInspectionHalcon01();

ConesInspectionHalcon01 ParameterOut = new ConesInspectionHalcon01();

ParameterIn.AreaAddSet = 50000;

ParameterIn.MaxAreaSet = 350;

ParameterIn.MaxEdgeSet = 150;

ParameterIn.AreaCutSet = 40000;

while (true)

{

if (threadFlag)

{

long start = DateTime.Now.Ticks;

ProjectCalculation.ConesInspectionHalcon02(test2, ParameterIn, out ParameterOut);

Thread.Sleep(1000);

}

}

}

线程3、4….10的线程处理函数一次类推。

ConesInspectionHalcon01函数:

public static void ConesInspectionHalcon01(Bitmap bitmap, ConesInspectionHalcon01 ParameterIn, out ConesInspectionHalcon01 ParameterOut)

{

Bitmap bm = (Bitmap)bitmap.Clone();

Stopwatch sw = new Stopwatch();

sw.Start();

HDevelopExport he = new HDevelopExport();

BitmapData bd = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height),

ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

IntPtr intp = bd.Scan0;

Bitmap b1 = new Bitmap(bm.Width, bm.Height, PixelFormat.Format8bppIndexed);

Bitmap b2 = new Bitmap(bm.Width, bm.Height, PixelFormat.Format8bppIndexed);

Bitmap b3 = new Bitmap(bm.Width, bm.Height, PixelFormat.Format8bppIndexed);

BitmapData bd1 = b1.LockBits(new Rectangle(0, 0, bm.Width, bm.Height),

ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

BitmapData bd2 = b2.LockBits(new Rectangle(0, 0, bm.Width, bm.Height),

ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

BitmapData bd3 = b3.LockBits(new Rectangle(0, 0, bm.Width, bm.Height),

ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

IntPtr intp1 = bd1.Scan0;

IntPtr intp2 = bd2.Scan0;

IntPtr intp3 = bd3.Scan0;

unsafe

{

Work.Correction.RGBToChannel(intp, intp1, intp2, intp3, bm.Width, bm.Height);

}

sw.Stop();

string tmp = sw.ElapsedMilliseconds.ToString();

Console.WriteLine(tmp);

sw.Reset();

// label2.Text = tmp;

bm.UnlockBits(bd);

HImage h1 = new HImage();

HImage h2 = new HImage();

HImage h3 = new HImage();

HTuple AreaCut, MaxArea, MaxEdge, AreaAdd;

HTuple hv_Gray, hv_Deviation;

sw.Start();

h1.GenImage1("byte", bm.Width, bm.Height, intp1);

h2.GenImage1("byte", bm.Width, bm.Height, intp2);

h3.GenImage1("byte", bm.Width, bm.Height, intp3);

sw.Stop();

tmp = sw.ElapsedMilliseconds.ToString();

Console.WriteLine(tmp);

sw.Reset();

try

{

sw.Start();

he.ScaleCircle(h1, h2, h3, out AreaAdd, out MaxArea, out MaxEdge, out AreaCut, out hv_Gray, out hv_Deviation);

sw.Stop();

tmp = sw.ElapsedMilliseconds.ToString();

Console.WriteLine(tmp);

sw.Reset();

}

catch (Exception ex)

{

AreaAdd = 1000000;

MaxArea = 1000000;

MaxEdge = 1000000;

AreaCut = 1000000;

hv_Gray = 0;

hv_Deviation = 0;

}

if (hv_Gray.D <= 30)

{

AreaAdd = 1000000;

MaxArea = 1000000;

MaxEdge = 1000000;

AreaCut = 1000000;

}

ParameterOut = new ConesInspectionHalcon01();

// ParameterOut=ParameterIn;

ParameterOut.CurrentAreaAdd = AreaAdd;

ParameterOut.CurrentAreaCut = AreaCut;

ParameterOut.CurrentMaxEdge = MaxEdge;

ParameterOut.CurrentMaxArea = MaxArea;

ParameterOut.hv_Gray = hv_Gray;

//    ParameterOut.hv_Deviation = hv_Deviation;

h1.Dispose();

h2.Dispose();

h3.Dispose();

b1.UnlockBits(bd1);

b2.UnlockBits(bd2);

b3.UnlockBits(bd3);

b1.Dispose();

b2.Dispose();

b3.Dispose();

if (ParameterOut.CurrentAreaAdd > ParameterIn.AreaAddSet

|| ParameterOut.CurrentMaxArea > ParameterIn.MaxAreaSet

|| ParameterOut.CurrentMaxEdge > ParameterIn.MaxEdgeSet

|| ParameterOut.CurrentAreaCut > ParameterIn.AreaCutSet)

{

ParameterOut.Result = false;

ParameterOut.Index = 10;

}

else

{

ParameterOut.Result = true;

ParameterOut.Index = 11;

}

//ParameterOut.Index = ParameterIn.Index;

if (bm != null) { bm.Dispose(); }

}

ConesInspectionHalcon02

ConesInspectionHalcon03 …ConesInspectionHalcon10和ConesInspectionHalcon01内容是一样的。

halcon图片上传到mysql_C# 10个线程并发执行Halcon图像算法 报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”...相关推荐

  1. showdialog 尝试读取或写入受保护的内存_轻松一键上4000MHz,XPG龙耀D50 重装RGB内存值不值得高端用户选购?...

    随着今年intel.AMD.nvidia分别推出旗下的高端硬件产品迭代提升,处理器和显卡性能也迎来了新的飞跃,对不少游戏玩家等高端用户来说,有了强劲的硬件,还需要高频内存才能补齐短板,让整机性能再上一 ...

  2. c# openCV图片传递-尝试读取或写入受保护的内存。这通常指示其他内存已损坏。解决方法

    未处理AccessViolationException 这通常指示其他内存已损坏,这里内存损坏并非物理的内存条损坏.猜想是执行到此步骤后,内存空间被清理了,没有找到内存地址的感觉. public st ...

  3. showdialog 尝试读取或写入受保护的内存_修改电压和时序,超频上3733,十铨火神3200 16G套装内存评测...

    十铨科技成立于1997,在存储当中算得上是老选手,但显然其名气不如金士顿.海盗船等,不过在内存老玩家心中,或许十铨的人气值更高,毕竟老玩家还是十分注重C/P值.同时十铨内存的终身质保服务给所有消费者提 ...

  4. SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传

    SpringMVC:学习笔记(10)--整合Ckeditor且实现图片上传 配置CKEDITOR 精简文件 解压之后可以看到ckeditor/lang下面有很多语言的js,如果不需要那么多种语言的,可 ...

  5. vue2.0_实现图片上传前进行压缩(约10倍)

    前言 1.以VantUI组件库中van-uploader文件上传为例 2.本例以图片大于2M才开始压缩,压缩条件可自行调节 3.压缩完成得到图片的base64格式,可转换成file文件 4.读取到图片 ...

  6. kindeditor4.1.10图片上传配置及使用说明

    1效果展示 1.1 点击图片上传按钮 1.2 弹出选择框,可以从已上传的图片中选择上传,也可以从本地上传. 1.3选择从图片空间上传,文件夹模式浏览所有已上传的图片 1.4从本地选择图片上传 1.5上 ...

  7. 简单的html网页图片上传,10个有用的HTML文件上传技巧

    上传文件的能力是许多Web和移动应用的关键需求,从将照片上传到社交媒体上到将简历发布到工作门户网站上,文件上传无处不在. 作为一名Web开发人员,我们一定知道HTML提供了原生文件上传的支持,并借助于 ...

  8. 4.CKeditor4.10.0最新图片上传配置

    CKeditor-4.10.0富文本编辑器,到上传图片的配置,网上的教程都不适合现在的版本. 第一步:在config.js的CKEDITOR.editorConfig = function( conf ...

  9. 第12章[12.10.1] Ext JS + CKEditor+Spring Boot 实现编辑器图片上传

    CKEditor 支持多种图片上传实现方式, 可以直接使用CKEditor 提供的云服务,不过这个服务是收费的, 而且上传的图片如果安全性要求较高,该方式可能不适合.本篇基于Spring Boot实现 ...

最新文章

  1. Netty详解(七):Netty 编解码以及消息头编解码器
  2. 复变函数与积分变换-手写笔记
  3. 50张非常精美的Apple主题桌面壁纸(上篇)
  4. 栈应用:实现二进制转八进制、十进制、十六进制
  5. Android Killer
  6. 栈和队列:2.队列(Queue)及其C语言实现
  7. ssh: Could not resolve hostname gitcafe.com: nodename nor servname provided, or not known
  8. 在Excel中插入Flash及解决不能自动播放问题
  9. 命令查询每个文件文件数
  10. 启动nginx出错:open() /var/run/nginx/nginx.pid failed (2: No such file or directory)
  11. python脚本报错:OSError: [WinError 193] %1 不是有效的 Win32 应用程序。
  12. 7 Web前端性能优化
  13. 物资仓库管理软件分析
  14. PR视频转场预设 10个快节奏极限运动空间扭曲效果PR转场过渡预设
  15. Oracle与MySQL的SQL语句区别
  16. 为什么要使用ABP框架?
  17. NOJ1060接苹果——DP
  18. 权威证明共识(Proof of Authority)
  19. win10下使用Linux(ubuntu18.04)
  20. 计算机日历教案,《认识日历》的教案

热门文章

  1. python文件输入符_python文件IO与file操作
  2. Linux表空间扩容,linux下oracle表空间导致磁盘空间不足
  3. 1-1圆柱体的表面积(算法竞赛入门经典)
  4. php 固话验证,收货地址参数校验:收货人、邮编、地址、手机、固话等
  5. apache根据ip分发_腾讯广告进入“IP新融点”时代
  6. WinCE中得Catalog Items前的标记图标的意义总结
  7. 深入浅出单实例Singleton设计模式
  8. android jni release,Android NDK 设置编译模式debug和release
  9. 【转】Net Framework,Net Core 和 Net Standard 区别
  10. C#多线程之旅(2)——详解线程的开始和创建