gpt4 book ai didi

c# - 多线程 .NET 应用程序导致在 64 位四核 Windows Server 上运行的 KERNEL32.dll 中出现应用程序错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:49 25 4
gpt4 key购买 nike

我有一个多线程 .NET 应用程序,它偶尔会在没有任何消息的情况下终止。当我检查日志时,有一个条目“KERNEL32.dll 中的应用程序错误”。是什么原因造成的?这是一些基本代码:

foreach (int id in ids)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessData), id);
}

ProcessData 方法如下所示:

private void ProcessData(object _id)
//Load some data from a database with id = _id
//Process that data and push it to another server using HTTP
//Increment a counter

Interlocked.Increment(ref counter);

//Update progress bar
try
{
// Invoke the delegate on the form.
this.Invoke(new BarDelegate(UpdateBar), counter);
}
catch {}
}

在某些情况下,可能有数百万个 ID 要处理。但是仅使用 10,000 个 ID 进行测试通常会导致所描述的应用程序错误。我这样做正确吗?

感谢您的帮助!

最佳答案

QueueUserWorkItem 是否总是返回 true?

此外,您是否在那个空捕获中得到任何异常?

关于c# - 多线程 .NET 应用程序导致在 64 位四核 Windows Server 上运行的 KERNEL32.dll 中出现应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1476488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com