Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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!

Posted
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 ;).

Nothing is as illusive as 'the last bug'.
Posted

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.

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...