May be we can't expect this in the right order? as they are "Threads!"?
You hit it spot on. Threads are scheduled by the system when to run and for how long. So what you are observing now is the expected behaviour, eventhough there might be circumstances where the order would be what you presumed first .
Did you also try the third alternative from the SO post I referenced in my solution attempt?
PS: Skip the Mr. stuff, we're all peers here on CP.
"I had the right to remain silent, but I didn't have the ability!"
I'm just letting the monkey go off my head at the moment as the code works with the ParametereizedThread start. Packing the code and sending it to my mates.
Once done, will come back to explore the method that you pointed out. cheers! Mr. Manfred
Threading is not deterministic in the order of execution unless you add constructs to synchronize your threads, e.g. Thread 2 waits for completion of Thread 1 before it starts, Thread 3 waits for completion of Thread 2 before it starts, etc. But that would defeat the purpose of threading, if you create threads to allow parallel execution, but then you serialize all of their execution.
(On a multi-core machine, they can even be scheduled to execute physically at the same time, which opens up a can of even more indeterministic behavior )
The problem is the lambda expression, it references the variable i of the outer method at the time of the thread execution, and that is likely after all threads are created. This is not like a passed parameter that gets copied at the time of the thread creation.
Try creating a thread that takes a parameter and pass the i there, this should resolve the issue.
No the problem is that you are using threads and you think that there should be an order.
It is simple - stopping thinking that. There is no order. It doesn't matter how you create them nor execute them - there still is no order.
If you want an order then you must assert that order yourself into the code.
HOW you do that depends on what you actually want to acheive. It could be as simple as just ordering the final set after processing of all the threads completes. Or providing a bucket into which each thread puts its result.
Sometimes the execution order does not matter, but the publishing of the result (e.g. if your processing takes significant time before results are available). In this case you should spinup the threads and let them execute in any order as they will, but when the results are available wait for the completion of the "previous" thread and then publish your results.
Using a pattern like this would allow to use the parallel execution of the long processing and still have the serialized behavior at time of the publishing of the results.
In last week, I wanted to make a presentation viewer(Slide show) using C#.
I went through MS-PowerPoint and its done but licensed(So not of my use).
MS-PowerPoint Viewer(No support in C#).
Then LibreOffice and OpenOfficeOrg- Too much complicated to use, having errors in libraries.
So what may be the best way to implement a presentation controller in my form.
I can use C# or C++.
Remove this post. It's VERY unlikely that the person you're addressing this to will ever see it and the only people interested in your email address are the spam bots that scan these forums pretty regularly looking for email addresses to send all kinds of spam to.
Post your question in the forum at the bottom of the article that you're talking about.
I am having issues with maintaining info when person uses browser back button. I work for a company which is an online traffic school course. The issues I am having is say a student starts on lesson 1. Within lesson 1 there are 10 pages of content that they must read and click Next button to go to next page. Once they then have read all 10 pages, then they go to a quiz where they are given one question at a time (there are 5 questions). They click Next button to move to each question. Once they have answered all questions, then they go to a grade page. If they passed, then they click on continue button to go to lesson 2. Then onto quiz for lesson 2. This part all works great and if they click our programmed Back buttons everything works great as well. The problem is if they go from say lesson 1 all the way to lesson 3 (just an example) and they decide to use the browser's back button to go all the way back to lesson 1, everything tends to get messed up. Since we are driving off of class Student which contains current lesson num, current page num, current question num, once we advance further in the course these values get updated. My problem is that when the student continuously clicks the browser's back button the lesson num, page num and question num (and other content) does not follow suit to what it was. I am not sure why, but the pages are not being cached. Is there anyway to maintain the lesson num, page num and question num as the student clicks browser back button? Meaning as they click back to quiz from lesson 2, it shows lesson 2 (it is currently showing lesson 3 since that is how far have advanced) and same with the lesson pages that they must read. I have tried to use hidden input, but it does not seem to work correctly all the time. Any ideas???
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
As others have said, this really should be in the ASP.NET forum. However, some food for thought for you - what you are looking at maintaining is effectively the maximum point they have reached. To this end, you might want to use a combination of the user Session and a database (if the user can log out and log back in) to hold this value.
I was brought up to respect my elders. I don't respect many people nowadays.
Our database maintains current lesson, page, question, advanced (furthest point reached) lesson, page, question, and max (furthest point to reach) lesson, page, question. As the student moves forward, the current and advanced values get set. For example, when the student views the lesson the .ASPX page displays lesson # and page #'s available in lesson with current page highlighted and the lesson content (the verbage they must read to pass the quizzes) for that lesson/page combo is displayed. As they move forward in the pages, the highlighted page # changes and the lesson content changes. Once they reach the max page for that lesson and they click on Next button, they then go to quiz. On quiz ASPX page, the lesson and question # are displayed (lesson # and question # are set by current lesson and current question values) as well as the associated question and possible answers. Once student then goes to lesson 2, current lesson # = 2, current page # = 1, advanced lesson # = 2 and advanced page # = 1. Now I have noticed different things happen based on what browser is being used. For example in Firefox, once student goes all the way through lesson 1, takes lesson 1 quiz, passes and goes to lesson 2. Now if student clicks browser back button everything seems to be ok, it appears to be cached. If student clicks browser back button to lesson 1 quiz question 2, everything seems to be ok. That is it shows Lesson 1 Question 2 with the appropriate question and possible answers (with their answer selected). However, if student goes all the way back to lesson 1 quiz question 1, it displays Lesson 2 question 1 but with lesson 1 question 1 question and answer. Now if student clicks on our programmed Next button, the program now thinks we are on lesson 2 quiz and next shows lesson 2 question 2 along with a question and possible answers that are indeed from lesson 2 and none of the answer radio buttons are set since have not taken lesson 2 quiz.
I would have thought that everything would have been cached. So no matter how many times I click browser back button from my furthest point it would be showing exact pages I went through in reverse order, but this is not the case. Any ideas???