本文介绍了需要伪代码/维护X个线程的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 使用VB.NET 2005,以及在双CPU盒上运行的Windows窗体,我需要 获取记录集(例如100,000条记录)并生成一个线程来处理 每条记录的互联网XML事务例程。这是一个很好的 使用线程,因为那些互联网请求是针对第三方 服务器,这些服务器通常有1秒的延迟问题,因此处理它们 多线程是获取 记录集中所有记录的最快方法。我想设置一个变量/常量来控制允许同时运行并允许代码保持的线程的数量 产生的线程数达到数字。然后,我可以使用那个数字和 找出最好的#个线程。但我不是线程专家 而且我不知道我对.NET 2.0框架有什么新的选择。我也没有找到任何一个例子,显示线程被重复产生到一个特定数字,以努力通过一个记录集。显然 每个线程完成后需要与主例程进行通信(触发 事件??)并且主例程需要接下来的记录并且将其抛给另一个线程。可以 有人请帮我用这个伪代码,或者更好的是,给我一个真正的代码示例指向我这个吗? 解决方案 添加 让我看看你是否理解你要做的事情: 你有100,000条记录在当地方面。对于每条记录,您必须要求b $ b发出网络请求。你认为你可以一次发出10个网页请求 以加快这个过程。 我明白为什么你认为线程可以加速这个,但是你可以更好地一次发送多个请求。我不确定你是否可以访问服务器端的东西,但是你应该设计你的xml到在一次发送中处理多个请求。然后你发送100,000个请求 并且只有延迟一次。 克里斯 With VB.NET 2005, and a Windows Form, running on a dual CPU box, I need totake a recordset (e.g. 100,000 records) and spawn a thread to handle aninternet XML transaction routine for each of the records. This is a niceuse of threading because those internet requests are going against 3rd partyservers that often have 1 second latency problems and so handling them withmultiple threads is the fastest way to get through all the records in therecordset. I''d like to set a variable/constant that controls the numberof threads that are allowed to run simultaneously and have the code keepspawning threads up to the number. Then, I can play with that number andfind out what # of threads works best. But I''m not the threading expertand I don''t know what new options I have with .NET 2.0 framework. I alsocan''t find any example that shows threads being repeatedly spawned up to acertain number in an effort to work through a single recordset. Obviouslyeach thread need to communicate back to the main routine when done (fire anevent??) and that main routine would need to then take the next record andthrow it to another thread, if # threads is less than max # threads. Cansomeone please help me with the pseudocode for this, or better yet, point meto a real code example that does this? 解决方案 equal be your AddingLet me see if I understand what you are trying to do:You have 100,000 records on the local side. For each record you have tomake a web request. Your thinking you can make 10 web requests at oncein order to speed up the process.Well I understand why you think threads would speed this up, but you''dbe better sending more than one request at a time. I''m not sure if youhave access to the server side stuff, but you should design your xml tohandle multiple requests in one send. Then you send in 100,000 requestsand only have the latency once.Chris 这篇关于需要伪代码/维护X个线程的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 09:35
查看更多