C#Express 2010线程化 [英] C# Express 2010 Threading

查看:49
本文介绍了C#Express 2010线程化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个Windows应用程序,我已经在c#Express 2008中运行了一年,并且一直在尝试将其转换为2010年的最后几天.我遇到的问题是,它是一个多线程应用程序,必须运行每秒的一系列代码.它的作用是有一个主线程,该线程调用3个工作线程,等待它们完成,然后进行一些其他处理,休眠直到1秒,然后再次运行.

问题是代码的一部分可以调用一个需要8秒钟才能响应的Web服务,因此可以使用ThreadPool.QueueUserWorkItem调用这段代码.问题是在2010年运行时,这部分代码被调用为主线程继续运行,但是当唤醒子线程时,它将挂起,直到Threadpool方法完成运行.

这在2008年从未发生过.有什么建议吗?到目前为止,我将那段代码放入了自己的线程中,而不是使用Threadpool,但出现了同样的问题.

Hi,

I have a windows app that I have been running in c# Express 2008 for a year and have been trying to convert it over the last few days to 2010. The problem I am having is it is a multi-threaded application that has to run a series of code every second. What it does is have a main thread, that calls 3 worker threads, waits for them to finish then does some additional processing, sleeps till 1 second and runs again.

The problem is part of the code can call a web service that takes 8 seconds to respond, so this bit of code gets called using ThreadPool.QueueUserWorkItem. The problem is when running in 2010 when this part of the code gets called the main thread continues to run but when it awakens the sub threads it hangs until the Threadpool method finishes running.

This never happens in 2008. Any suggestions? So far I put that bit of code in it''s own thread rather than using Threadpool but same issue.

推荐答案

我认为这与.NET有关. net framework 4.如果您是我,我将不得不再次检查您使用的功能是线程安全的,不同步的,并且没有使用锁来阻止执行.开始注释一些代码行,以帮助您识别问题.
I think it has something to do with the .net framework 4. If i were you, i will have to check again that the functions you are using are thread-safe, not synchronized and no locks are used to block the execution. Start commenting some code lines to help you identify the problem.


这篇关于C#Express 2010线程化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆