有一个容器A 启动一个线程T1不停的往A里面加数据 另外在启动一个线程T2不停的将A里面的数据放到新建的容器B(每次都新建)里面,然后将容器A清空,但是T2的速度没有T1快导致容器A超极限内存溢出,有什么办法可以处理。
static void Thread1()
{
while (true)
{
//lock(_LsInt)
//{
_LsInt.Add(1); //}
} }
static void Thread2()
{
while (true)
{
List<int> lse = new List<int>();
lse.AddRange(_LsInt.ToArray());
_LsInt.Clear();
}
}
static void Thread1()
{
while (true)
{
//lock(_LsInt)
//{
_LsInt.Add(1); //}
} }
static void Thread2()
{
while (true)
{
List<int> lse = new List<int>();
lse.AddRange(_LsInt.ToArray());
_LsInt.Clear();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货