tommyb Posted July 14, 2004 Posted July 14, 2004 Hi, I'm new to this subject. Who can post a very simple example of multi-threading in asp.net (if possible C#)? Thanks you very much! Tommy. Quote
Administrators PlausiblyDamp Posted July 14, 2004 Administrators Posted July 14, 2004 Is there a particular problem you have or an idea for what you need multithreading for? Quite often multithreading in a web app will not behave as you would expect due to the way HTTP requests are handled. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
tommyb Posted July 14, 2004 Author Posted July 14, 2004 I have a web application with a dbase query. This takes some time. I just want to inform the user that the query is started. That's why I want to use multi-threading. First thread on the background processing the query. Second thread sending a message to the client (=changing the text of a label on the same page into "please wait.."). Is this possible? Thankx! Quote
Wile Posted July 14, 2004 Posted July 14, 2004 I have a web application with a dbase query. This takes some time. I just want to inform the user that the query is started. That's why I want to use multi-threading. First thread on the background processing the query. Second thread sending a message to the client (=changing the text of a label on the same page into "please wait.."). Is this possible? Thankx! You do realize that if 100 users go to that page at the same time you get a 100 threads all running the same query on the server? Anyway, some code to start a thread to do some heavy calculation. I used this in a windows form based applications so you probably have to rearrange the thread to an object that remains in memory after the user request the page, and can return the results to the user when he refreshes the page after the thread is finished. First the declaration of the thread and thread starter. private ThreadStart m_objStarter = null; private Thread m_objWorker = null; Somewhere along the line I decide to start the background thread. //ensure the thread is not started a second time. if (null == m_objWorker) { //Create the thread starter object. It points to the DoTheLongStuff method that does the long stuff. m_objStarter = new ThreadStart(DoTheLongStuff); //Create a new thread. m_objWorker = new Thread(m_objStarter); //Start the new thread m_objWorker.Start(); } Looking back at the code after a month, you dont need to make the thread starter a member object. Oh well, we all have to learn ;). Quote Nothing is as illusive as 'the last bug'.
Arch4ngel Posted July 14, 2004 Posted July 14, 2004 Think about Global class. A thread in this section might give good result. However... make sure data isn't used by your pages or you might find problem with accessing the same data. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.