线程问题 [英] Problem with Threading

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

问题描述

大家好,
是第一次发布者,但是已经多次使用Msdn论坛来解决问题!我的问题是:-我试图从一个线程中调用一个线程,它似乎出了问题.现在让我进一步解释.我有压力测试程序,需要将大量请求发送到Web服务.显然,仅使用一个线程列表限制了我在一秒钟内可以向服务抛出的请求数量.因此,我的明智之举是拥有一个激活时的线程列表,然后触发包含测试的线程列表.因此,我可以说3个线程,每个线程触发了200个测试线程.然后,我希望看到结果以某种顺序返回,例如1.1、2.1、1.2、3.1、2.2等(其中第一个数字是父线程ID,第二个数字是子线程ID).但是,在进行了一些调试之后,线程运行了1.1、1.2、1.3 ... 2.1、2.2、2.2 ....我似乎无法理解为什么会发生这种情况.父线程异步运行,然后子线程又异步运行.
谁能阐明为什么会这样,也许我应该怎么做才能得到预期的结果-这是能够触发很多的测试线程,以便我进行锤击我正在测试的Web服务.

非常感谢所有帮助-这是我的代码如何悬挂在一起的简短示例:

Hi All,
First time poster, but have used the Msdn forums on more than one occasion to solve problems!  My problem is this :- I am attempting to call a thread from a thread, and it appears to be going wrong.  Now let me explain a little further.  I have stress test program that needs to fire lots of requests to a web service.  Obviously using just one list of threads limits the amount of requests that I can throw at the service in 1 second.  So, my bright idea was to have a list of threads that when activated, would fire off a list of threads that contained the tests.  So, I could have say 3 threads that each fired off 200 testing threads.  I would then expect to see the results coming back in some sort of order such as 1.1, 2.1, 1.2, 3.1, 2.2 etc (where first digit is parent thread id & second digit is the child thread id).  However, having done some debugging, the threads are run 1.1, 1.2, 1.3 ... 2.1, 2.2, 2.2 ...  I can't seem to get my head around why this should happen.  The parent threads are run asynchronously and then so are their child threads in turn run asynch. 
Can anyone shed light on why this is happening and maybe how I should be doing this to get the desired result - which is to be able to fire off a lot of test threads so I can hammer the web service I am testing.

All help is greatly appreciated - here is a brief sample of how my code is hung together :

  

<身体>
< FONT color =#0000ffsize = 2>< FONT color =#0000ffsize = 2>
< P> public </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2>部分</FONT</FONT> < FONT color =#0000ffsize = 2>< FONT color =#0000ff
size = 2> class </FONT></FONT> < FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2> MainForm</FONT>/FONT>< FONT·size = 2> :</FONT>< FONT color =#2b91af
size = 2>< FONT color =#2b91afsize = 2>表单< BR>/FONT></FONT>< FONT
size = 2> {< BR></FONT>< FONT color =#0000ff size = 2>< FONT color =#0000ff
size = 2> 私有 </FONT></FONT> < FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2>列表</FONT>/FONT>< FONT·size = 2></FONT>< FONT color =#2b91af
size = 2>< FONT颜色=#2b91af&size = 2> ParentTestThread</FONT></FONT>< FONT
size = 2& gt; parentTestThreadList;</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" </P>
< Pdir = ltrstyle = <字体颜色=蓝色>" MARGIN-RIGHT:0px" ></FONT>< FONT颜色=#0000ff大小= 2>< FONT
color =#0000ff́size = 2> private </FONT>< ;/FONT> < FONT color =#2b91afsize = 2>< FONT
color =#2b91afsize = 2>列表</FONT>/FONT< FONT< size = 2><</FONT>< FONT color =#0000ff size = 2>< FONT color =#0000ff size = 2> int < Pdir = ltrstyle = " MARGIN-RIGHT:́0px" </FONT>< FONT颜色=#0000ff尺寸= 2>< FONT
color =#0000ff size = 2> 私有 </FONT></FONT> < FONT color =#0000ffsize = 2>< FONT
color =#0000ff́size = 2> int </FONT>< ;/FONT< FONTsize = 2> totalThreads1 = 10;</P>
< Pdir = ltrstyle = <字体颜色=蓝色>" MARGIN-RIGHT:0px" ></FONT>< FONT颜色=#0000ff大小= 2>< FONT
color =#0000ff́size = 2> private </FONT>< ;/FONT> < FONT color =#0000ffsize = 2>< FONT
color =#0000ff́size = 2> int </FONT></FONT>< FONT́size = 2> ; totalThreads2 =
10;< BR>< BR>.< BR>.< BR>.< BR>< FONT color =#0000ffff size = 2>< ; FONT color =#0000ff
size = 2> public </FONT></FONT>< FONT·size = 2> MainForm()</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" > {</FONT>< FONT size = 2></P>
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" > threadTotalsList ==</FONT> < FONT
color =#0000ff size = 2>< FONT color =#0000ff size = 2> new size = 2>& lt;/FONT>< FONT color =#0000ff&size = 2>< FONT color =#0000ff< td>
size = 2> int </FONT></FONT>< FONT·size = 2>& gt ;();</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" > parentTestThreadList ==</FONT>< FONT
color =#0000ffsize = 2>< FONT color =#0000ffsize = 2> new </FONT> </FONT> < FONT
color =#2b91afsize = 2>< FONT color =#2b91afsize = 2>列表</FONT></FONT>< FONT /tr>
size = 2><</FONT>< FONT color =#2b91af size = 2>< FONT color =#2b91af
size = 2> ParentTestThread</FONT></FONT>< FONT size = 2>& gt;();</P>
< Pdir = ltrstyle = <字体颜色=蓝色>" MARGIN-RIGHT:0px" > threadTotalsList.Add(totalThreads1); </P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" > threadTotalsList.Add(totalThreads2);</P>
< Pdir = ltrstyle = <字体颜色=蓝色>" MARGIN-RIGHT:0px" ></FONT>< FONT颜色=#0000ff大小= 2>< FONT
color =#0000ff́size = 2> 用于 </FONT>< ;/FONT< FONTsize = 2> (</FONT>< FONT color =#0000ff
size = 2>< FONT color =#0000ff&size = 2> int </FONT></FONT> ;< FONT́size = 2> i = 0;我& lt;
threadTotalsList.Count; i ++)</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" > {</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" > parentTestThreadList.Add(</FONT>< FONT
color =#0000ffsize = 2>< FONT color =#0000ffsize = 2> new </FONT> </FONT> < FONT
color =#2b91af size = 2>< FONT color =#2b91af
size = 2> ParentTestThread</FONT></FONT>< FONT·size = 2>(threadTotalsList [i],i +
1));</P>
< Pdir = ltrstyle = "MARGIN-RIGHT:0px"" < Pdir = ltrstyle = " MARGIN-RIGHT:́0px" >}< BR>}< BR</P>< FONT size = 2>
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" ></FONT>< FONT颜色=#0000ff大小= 2>< FONT
color =#0000ff́size = 2> private </FONT>< ;/FONT> < FONT color =#0000ffsize = 2>< FONT
color =#0000ffsize = 2> void </FONT></FONT>< FONT́size = 2> ;
runTestsButton_Click(</FONT>< FONT color =#0000ffsize = 2>< FONT color =#0000ff
size = 2> 对象 </FONT></FONT>< FONT·size = 2>发件人</FONT>< FONT color =#2b91af
size = 2< FONT color =#2b91afsize = 2> EventArgs</FONT>/FONT>< FONT size = 2> e)/P
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" > {</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px"
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" >< FONTsize = 2> </P></FONT>< FONT color =#0000ff
size = 2>< FONT color =#0000ffÂsize= 2> foreach </FONT></FONT< FONT size = 2>
(</FONT>< FONT color =#2b91af.size = 2>< FONT color =#2b91af
size = 2> ParentTestThread</FONT></FONT>< FONT·size = 2>线程</FONT>< FONT
color =#0000ffsize = 2>< FONT color =#0000ffsize = 2> in </FONT> </FONT>< FONT·size = 2>
parentTestThreadList)
< P</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" > {</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" > thread.RunWorkerCompleted + =< /FONT>< FONT
color =#0000ff size = 2>< FONT color =#0000ff size = 2> new size = 2> RunWorkerCompletedEventHandler</FONT></FONT>< FONT
size = 2>(thread_RunWorkerCompleted);</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" > thread.ChildThreadComplete + =</FONT>< FONT
color =#0000ffsize = 2>< FONT color =#0000ffsize = 2> new </FONT> </FONT> < FONT
color =#2b91af size = 2>< FONT color =#2b91af
size = 2> ChildThreadCompleteEventHandler</FONT></FONT>< FONT
size = 2>(thread_ChildThreadComplete);</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" > thread.RunWorkerAsync();< ;/P>
< Pdir = ltrstyle = " MARGIN-RIGHT:́0px" >}</P>
< Pdir = ltrstyle = " MARGIN-RIGHT:0px" >}< BR>< /P</FONT>
< P>< BR>然后::< BR>< FONT color =#0000ffsize = 2>< FONT color =#0000ffffsize = 2>< ;/P>
< P> public </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> class </FONT></FONT> < FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2> ParentTestThread</FONT>/FONT>< FONT·size = 2> :</FONT>< FONT color =#2b91af
size = 2>< FONT color =#2b91af&size = 2> BackgroundWorker</FONT></FONT>< FONT
size = 2</P>
< P> {</FONT>< FONT color =#0000ff&size = 2>< FONT color =#0000ff&size = 2></P>
< P> 受保护的 </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> 覆盖 </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> void </FONT></FONT>< FONT·size = 2> OnDoWork(</FONT>< FONT color =#2b91af
size = 2>< FONT颜色=#2b91af&size = 2> DoWorkEventArgs</FONT></FONT>< FONT·size = 2>
e)</P>
< P> {</P>
< P>//FONT>< FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> 尝试 </FONT></FONT> < FONTsize = 2></P>
< P> {</P>
< P></FONT>< FONT color =#0000ff́size = 2>< FONT color =#0000ff
size = 2> foreach </FONT></FONT>< FONTsize = 2> (</FONT>< FONT color =#2b91af
size = 2< FONT color =#2b91afsize = 2> RunTestThread</FONT></FONT>< FONT size = 2>
线程</FONT>< FONT color =#0000ff́size = 2>< FONT color =#0000ff
size = 2> </FONT></FONT> < FONT尺寸= 2> testThreadList)</P>
< P> {</P>
< P> thread.RunWorkerCompleted + =</FONT>< FONT color =#0000ffsize = 2>< FONT
color =#0000ff́size = 2> </FONT></FONT> < FONT color =#2b91afsize = 2>< FONT
color =#2b91af size = 2> RunWorkerCompletedEventHandler</FONT></FONT>< FONT
size = 2>(thread_RunWorkerCompleted);</P>
< P> thread.RunWorkerAsync(testArgumentList [testThreadList.IndexOf(thread)]);</P>
< P>}</P>
< P>}< BR></P>
< P>和最后:< BR>< FONT color =#0000ffsize = 2>< FONT color =#0000ffsize = 2></P>
< P> public </FONT></FONT> < FONT color =#0000ffsize = 2>< FONT color =#0000ff
size = 2> class </FONT></FONT> < FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2> RunTestThread</FONT></FONT>< FONT·size = 2> :</FONT>< FONT color =#2b91af
size = 2>< FONT颜色=#2b91af< size = 2> BackgroundWorker</FONT></FONT>< FONT
size = 2></P>
< P> {</FONT>< FONT color =#0000ff&size = 2>< FONT color =#0000ff&size = 2</P>
< P> 受保护的 </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> 覆盖 </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> void </FONT></FONT> < FONT尺寸= 2> OnDoWork(</FONT>< FONT color =#2b91af
size = 2>< FONT颜色=#2b91af; size = 2> DoWorkEventArgs</FONT</FONT>< FONT·size = 2>
e)</P>
< P> {< BR</P>
< P>.< BR>/FONT>.< BR>.< BR>< FONT color =#0000ffff size = 2> FONT color =#0000ff
size = 2</P>
< P> ... </FONT>< /FONT> < FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2> RunTestThreadCompleted</FONT>/FONT>< FONT·size = 2>(</FONT>< FONT color =#a31515 size = 2>< FONT颜色=#a31515 size = 2> " WebException
Raised" </FONT></FONT>< FONT·size = 2> +消息,serviceConnected,testPassed,
</FONT>< FONT颜色=#0000ff尺寸= 2>< FONT颜色=#0000ff尺寸= 2> </FONT></FONT>
< FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2> TimeSpan</FONT></FONT>< FONT size = 2>(),threadName,threadNumber);</P>
< P>/FONT>< FONT color =#0000ff&size = 2>< FONT color =#0000ff&size = 2></P>
< P> 受保护的 </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> 覆盖 </FONT></FONT> < FONT color =#0000ff尺寸= 2>< FONT color =#0000ff
size = 2> void </FONT></FONT> < FONT尺寸= 2> OnRunWorkerCompleted(</FONT>< FONT
color =#2b91af size = 2< FONT color =#2b91af
size = 2> RunWorkerCompletedEventArgs</FONT></FONT>< FONT size = 2> e)/P
< P> {</P>
< P></FONT>< FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2> RunWorkerCompletedEventArgs</FONT>/FONT< FONT size = 2> workerComplete =
</FONT>< FONT颜色=#0000ff尺寸= 2>< FONT颜色=#0000ff尺寸= 2> </FONT></FONT>
< FONT color =#2b91afsize = 2>< FONT color =#2b91af
size = 2> RunWorkerCompletedEventArgs</FONT></FONT>< FONT size = 2>(已完成,
e.Error,e.Cancelled);</P>
< P></FONT>< FONT color =#0000ff́size = 2>< FONT color =#0000ff
size = 2> base </FONT></FONT>< FONTsize = 2> .OnRunWorkerCompleted( workerComplete);</P>
< P>}</P</FONT>/FONT>/FONT</FONT>
<FONT color=#0000ff size=2><FONT color=#0000ff size=2>  
<P>public</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>partial</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>class</FONT></FONT> <FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>MainForm</FONT></FONT><FONT size=2> : </FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>Form<BR></FONT></FONT><FONT   
size=2>{<BR></FONT><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>private</FONT></FONT> <FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>List</FONT></FONT><FONT size=2>&lt;</FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>ParentTestThread</FONT></FONT><FONT   
size=2>&gt; parentTestThreadList;</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px"></P>  
<P dir=ltr style="MARGIN-RIGHT: 0px"></FONT><FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>private</FONT></FONT> <FONT color=#2b91af size=2><FONT   
color=#2b91af size=2>List</FONT></FONT><FONT size=2>&lt;</FONT><FONT   
color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT   
size=2>&gt; threadTotalsList;</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px"></FONT><FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>private</FONT></FONT> <FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>int</FONT></FONT><FONT size=2> totalThreads1 = 10;</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px"></FONT><FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>private</FONT></FONT> <FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>int</FONT></FONT><FONT size=2> totalThreads2 =   
10;<BR><BR>.<BR>.<BR>.<BR><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>public</FONT></FONT><FONT size=2> MainForm()</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">{</FONT><FONT size=2></P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">threadTotalsList = </FONT><FONT   
color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT> <FONT   
color=#2b91af size=2><FONT color=#2b91af size=2>List</FONT></FONT><FONT   
size=2>&lt;</FONT><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>int</FONT></FONT><FONT size=2>&gt;();</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">parentTestThreadList = </FONT><FONT   
color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT> <FONT   
color=#2b91af size=2><FONT color=#2b91af size=2>List</FONT></FONT><FONT   
size=2>&lt;</FONT><FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>ParentTestThread</FONT></FONT><FONT size=2>&gt;();</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">threadTotalsList.Add(totalThreads1);</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">threadTotalsList.Add(totalThreads2);</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px"></FONT><FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>for</FONT></FONT><FONT size=2> (</FONT><FONT color=#0000ff   
size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i = 0; i &lt;   
threadTotalsList.Count; i++)</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">{</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">parentTestThreadList.Add(</FONT><FONT   
color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT> <FONT   
color=#2b91af size=2><FONT color=#2b91af   
size=2>ParentTestThread</FONT></FONT><FONT size=2>(threadTotalsList[i], i +   
1));</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">threadCount += threadTotalsList[i] + 1;</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">}<BR>}<BR></P><FONT size=2>  
<P dir=ltr style="MARGIN-RIGHT: 0px"></FONT><FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>private</FONT></FONT> <FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>void</FONT></FONT><FONT size=2>   
runTestsButton_Click(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>object</FONT></FONT><FONT size=2> sender, </FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>EventArgs</FONT></FONT><FONT size=2> e)</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">{</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">.<BR>.<BR>.<BR></FONT>  
<P dir=ltr style="MARGIN-RIGHT: 0px"><FONT size=2></P></FONT><FONT color=#0000ff   
size=2><FONT color=#0000ff size=2>foreach</FONT></FONT><FONT size=2>   
(</FONT><FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>ParentTestThread</FONT></FONT><FONT size=2> thread </FONT><FONT   
color=#0000ff size=2><FONT color=#0000ff size=2>in</FONT></FONT><FONT size=2>   
parentTestThreadList)  
<P></P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">{</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">thread.RunWorkerCompleted += </FONT><FONT   
color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT> <FONT   
color=#2b91af size=2><FONT color=#2b91af   
size=2>RunWorkerCompletedEventHandler</FONT></FONT><FONT   
size=2>(thread_RunWorkerCompleted);</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">thread.ChildThreadComplete += </FONT><FONT   
color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT> <FONT   
color=#2b91af size=2><FONT color=#2b91af   
size=2>ChildThreadCompleteEventHandler</FONT></FONT><FONT   
size=2>(thread_ChildThreadComplete);</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">thread.RunWorkerAsync();</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">}</P>  
<P dir=ltr style="MARGIN-RIGHT: 0px">}<BR></P></FONT>  
<P><BR>Then :<BR><FONT color=#0000ff size=2><FONT color=#0000ff size=2></P>  
<P>public</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>class</FONT></FONT> <FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>ParentTestThread</FONT></FONT><FONT size=2> : </FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>BackgroundWorker</FONT></FONT><FONT   
size=2></P>  
<P>{</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2></P>  
<P>protected</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>override</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>void</FONT></FONT><FONT size=2> OnDoWork(</FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>DoWorkEventArgs</FONT></FONT><FONT size=2>   
e)</P>  
<P>{</P>  
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>try</FONT></FONT><FONT size=2></P>  
<P>{</P>  
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>foreach</FONT></FONT><FONT size=2> (</FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>RunTestThread</FONT></FONT><FONT size=2>   
thread </FONT><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>in</FONT></FONT><FONT size=2> testThreadList)</P>  
<P>{</P>  
<P>thread.RunWorkerCompleted += </FONT><FONT color=#0000ff size=2><FONT   
color=#0000ff size=2>new</FONT></FONT> <FONT color=#2b91af size=2><FONT   
color=#2b91af size=2>RunWorkerCompletedEventHandler</FONT></FONT><FONT   
size=2>(thread_RunWorkerCompleted);</P>  
<P>thread.RunWorkerAsync(testArgumentList[testThreadList.IndexOf(thread)]);</P>  
<P>}</P>  
<P>}<BR></P>  
<P>And Finally :<BR><FONT color=#0000ff size=2><FONT color=#0000ff size=2></P>  
<P>public</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>class</FONT></FONT> <FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>RunTestThread</FONT></FONT><FONT size=2> : </FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>BackgroundWorker</FONT></FONT><FONT   
size=2></P>  
<P>{</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2></P>  
<P>protected</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>override</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>void</FONT></FONT><FONT size=2> OnDoWork(</FONT><FONT color=#2b91af   
size=2><FONT color=#2b91af size=2>DoWorkEventArgs</FONT></FONT><FONT size=2>   
e)</P>  
<P>{<BR></P>  
<P>.<BR></FONT>.<BR>.<BR><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2></P>  
<P>... new</FONT></FONT> <FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>RunTestThreadCompleted</FONT></FONT><FONT size=2>(</FONT><FONT   
color=#a31515 size=2><FONT color=#a31515 size=2>"WebException 
Raised"</FONT></FONT><FONT size=2> + message, serviceConnected, testPassed,   
</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT>   
<FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>TimeSpan</FONT></FONT><FONT size=2>(), threadName, threadNumber);</P>  
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>&nbsp;</P>  
<P>protected</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>override</FONT></FONT> <FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>void</FONT></FONT><FONT size=2> OnRunWorkerCompleted(</FONT><FONT   
color=#2b91af size=2><FONT color=#2b91af   
size=2>RunWorkerCompletedEventArgs</FONT></FONT><FONT size=2> e)</P>  
<P>{</P>  
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>RunWorkerCompletedEventArgs</FONT></FONT><FONT size=2> workerComplete =   
</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT>   
<FONT color=#2b91af size=2><FONT color=#2b91af   
size=2>RunWorkerCompletedEventArgs</FONT></FONT><FONT size=2>(completed,   
e.Error, e.Cancelled);</P>  
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff   
size=2>base</FONT></FONT><FONT size=2>.OnRunWorkerCompleted(workerComplete);</P>  
<P>}</P></FONT></FONT></FONT></FONT> 

推荐答案

我认为您需要重新发布代码...


I think you need to repost your code...



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

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