问题现象
- 预:开启线程超过1000多;
- 程序运行时抛出异常,且未开启预期1000多线程;
- 程序运行时,cpu、内存占用均较小;cpu 30%,内存 300M;
- x64程序运行正常,x86程序运行则报 'System.OutOfMemoryException';
错误:
Exception of type 'System.OutOfMemoryException'
启动采集线程时异常
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Threading.Thread.StartInternal(ThreadHandle t, Int32 stackSize, Int32 priority, Char* pThreadName)
at System.Threading.Thread.StartCore()
at System.Threading.Thread.Start()
at ***.StartThread() in ***.cs:line 234
at ***.<>c__DisplayClass13_1.<CreateDeviceThread>b__0(Device d) in ***.cs:line 165
解决方法
Thread t = new Thread(work, 512);
api 参考: