when is the sleeping thread of the parent thread also sleeping?
Now the main thread is the user interface. I create 20 subpages inside the main thread with the factory task (allows you to call threads 2) Inside these 20 subtypes, I again create 10 more subtopics with the sub factory (allows you to call threads 3)
Now inside these threads 2 I have an infinite loop. Inside an infinite loop, it checks to see if threads 3 are complete or not. If completed, delete the completed thread and start another thread. I use a 250 ms sleep for every check inside an infinite loop. Therefore, when threads 2 in a dream, threads 3 also do not work or they are independent. Here is the code you can see.
while (true) { int irActiveThreadCount = 0; int irFinishedLast = -1; for (int i = 0; i < irPerMainSiteThreadCount; i++) { if (MainSitesTaskList[irWhichMainTask, i] == null) { irFinishedLast = i; break; } if (MainSitesTaskList[irWhichMainTask, i].IsCompleted == true) { irFinishedLast = i; break; } } for (int i = 0; i < irPerMainSiteThreadCount; i++) { if (MainSitesTaskList[irWhichMainTask, i] != null) if (MainSitesTaskList[irWhichMainTask, i].IsCompleted == false) { irActiveThreadCount++; } } if (irFinishedLast > -1) { var newTask = Task.Factory.StartNew(() => { fcStartSubPageCrawl(srMainSiteURL, srMainSiteId, irWhichMainTask); }); lock (lockerMainSitesArray) { if (MainSitesTaskList[irWhichMainTask, irFinishedLast] != null) MainSitesTaskList[irWhichMainTask, irFinishedLast].Dispose(); MainSitesTaskList[irWhichMainTask, irFinishedLast] = newTask; } } Thread.Sleep(250); srQuery = "myquery"; using (DataSet dsTemp = DbConnection.db_Select_Query(srQuery)) { if (dsTemp != null) if (dsTemp.Tables.Count > 0) if (dsTemp.Tables[0].Rows.Count == 0) { break; } } }
source share