Home > Net >  O top cow B bosses give directions!!!!!! C # multithreaded issues.
O top cow B bosses give directions!!!!!! C # multithreaded issues.

Time:02-26

Create a thread
 
Int taskn=0;
Task [] tasks=new Task [5].
while (! Jpgfile. EndOfStream)//download
{
Imurl=jpgfile. ReadLine ();
If (taskn & lt; 5)
{
The tasks [taskn]=Task. Run (()=& gt; Getpic (imurl));
Console. WriteLine (" download address: "+ taskn + imurl);
//Thread. Sleep (500);//sleep function
Taskn++;
}
}
The Console. ReadKey ();


The thread function
 
The static bool Getpic (string imurl)
{
Console. WriteLine (" thread address: "+ imurl);
Return await Task. Run (()=& gt;
{WebClient download file,,,,,,


Don't sleep function results are as follows, have all the time, repeat, repeat the same are not
Download address: 0, 65026
Download address: 65027
1Download address: 65028
2Download address: 65029
Download address: 65030
Thread address: 65029
Thread address: 65031
Thread address: 65029
Thread address: 65031
Thread address: 65031

Use the sleep function is normal, don't know where is wrong, please give directions

Download address: 0, 65026
Thread address: 65026
Download address: 65027
1Thread address: 65027
Download address: 65028
2Thread address: 65028
Download address: 65029
Thread address: 65029
Download address: 65030
Thread address: 65030


  •  Tags:  
  • C#
  • Related