本文介绍了使用ThreadPool实现多线程的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

大家好,

我正在实现多线程.
我正在逐行读取文本文件中的数据,然后使用线程进一步处理这些行.
下面是我的示例代码:

Hi All,

I am implementing multithreading.
I am reading data from a text file line by line and then using threads to process these lines further.
Below is my sample code:

public void HandleRequest(TextReader reader)
{
            string line = "";
            while ((line = reader.ReadLine()) != null)
            {
                string[] arrUserInfo = line.Split(new char[] { ',' });
                try
                {
                    Thread objThread = new Thread(new ParameterizedThreadStart(this.Add));
                    objThread.Start((object)arrUserInfo);
                }
                catch (Exception ex)
                {
                }
            }
       }

public void Add(object arrUserInfo)
{
    //Do something
}



在运行了1000行应用程序后,我发现如果不使用线程,其性能也不会有太大差别.
我想提高应用程序的性能.
我在Google上阅读到ThreadPool可能会有所帮助.
我提到了 http://www.switchonthecode.com/tutorials/csharp-tutorial-using-the-线程池的[ ^ ]文章. br/>但是我无法理解如何在我的应用程序中实现ThreadPool,因为ThreadPool使用For循环,而我的应用程序已经使用while循环从文本文件中读取行.

任何人都可以在这里帮助我.

谢谢,
Nagendra.



After running application for 1000 lines, i found out that its performance is not much different if we don''t use threads.
I want to improve the performance of my application.
I read on google that ThreadPool can be helpful.
I referred http://www.switchonthecode.com/tutorials/csharp-tutorial-using-the-threadpool[^] article for ThreadPool.
But i am not able to understand how can i implement ThreadPool in my application because ThreadPool uses a For loop and my application already using a while loop to read lines from text file.

Can anyone help me here.

Thanks,
Nagendra.

推荐答案


这篇关于使用ThreadPool实现多线程的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 06:00