multithreading ASP.NET

T

tommy

hi,

i have found a example for multithreading and asp.net

http://www.fawcette.com/vsm/2002_11/magazine/features/chester/

i want to speed up my website ...

if my website is starting, they should build a database-connection and
send a few sqls

the code works fine without multithreading--- but if i call the method
as the example..:

Dim NewThread As Thread = New Thread(AddressOf threading)
NewThread.Priority = ThreadPriority.Lowest
NewThread.Start()

.....i get an error--means i have not set a objectreference
in the method i call a class, who´s calling the access-database

the error raise at - setting the connection-string

oledbconnection1.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data
Source=" & Server.MapPath("/~db/db.mdb") & _
";Mode=Share Deny None;Extended Properties=""""" & _
";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet
OLEDB:Database Pass" & _
"word="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking
Mode=1;Jet OLEDB:Glob" & _
"al Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet
OLEDB:New Databas" & _
"e Password="""";Jet OLEDB:Create System Database=False;Jet
OLEDB:Encrypt Database=" & _
"False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet
OLEDB:Compact Without Rep" & _
"lica Repair=False;Jet OLEDB:SFP=False"

any suggestions??


regards

tommy
 
S

Scott Allen

Hi tommy:

The OleDbConnection variable must be null. Did you New it? Follow the
code with the debugger.

I'd strongly advise you to not look to threading first to improve the
performance of your web site. Look at other areas first - caching for
instance can make dramatic performance improvements with relatively
little work. The article was slanted towards saying threading is
always a performance gain, and this is not true. Adding threads in
ASP.NET can make things worse in some scenarios, and there are easier
ways to gain perf.

Take a look at this guide:

Improving .NET Application Performance and Scalability
http://www.microsoft.com/downloads/...4D-F30E-4E72-B531-75384A0F1C47&displaylang=en
 
G

Guest

Multithreading should be the last resort in ASP.NET application. Before going
there try to optimize your code or database with indexes. Multithreading in a
web application will usually get you in more trouble.
 
J

John Saunders

tommy said:
hi,

i have found a example for multithreading and asp.net

http://www.fawcette.com/vsm/2002_11/magazine/features/chester/

i want to speed up my website ...

Do not use this example!!!

First of all, I strongly suggest you ignore any article about _using_ a
feature if it has to spend most of its time explaining what the feature
_is_. Most of that article attempts to teach what threads are!

Second, the GeneratePrimeNumbers() method references "Session". Within a web
form, "Session" refers to "Page.Session". This will be problematic when this
code is still executing after the Page has finished executing and the Page
instance has been deleted or trashed by ASP.NET. ASP.NET does not guarantee
you that the Page will be in any way useful after it is finished executing.
In particular, nothing should be referencing that Page or anything on it
after Page.Dispose has been called.

The code then proceeds to reference other member variables of the Page!

The author does not demonstrate an understanding of the ASP.NET page
lifecycle. I strongly recommend that you do better than the author and learn
how ASP.NET works with features it actually supports before you try to use
it with features for which it provides no support at all, namely
multithreading. Otherwise, you'll find yourself implementing this
misunderstanding of ASP.NET in an application where it actually matters,
instead of in a prime number generation program.
 
T

Tien

You can create more threads in your ASP.NET application in normal way,
and the thread still run even there is no active session :)
 
R

RASTA

hello,

thank you all for reply.

the "why" i want to do this is, because i have a forum-website -- where
the contributions are hierarchically.

for every node, i have to send a sql to database
for more contributions, the display of website takes more time

so i want to display the website at request--- and for every database
return, i referesh the site....


regards

tommy
----------------------------------------
HangulHanjaFastConversion-Eigenschaft

True if Microsoft Word automatically converts a word with
only one suggestion during conversion between hangul
and hanja. Read/write Boolean.
 
S

Scott Allen

My guess is you'll find more perf improvements by using caching, and
by optimizing the SQL to avoid a query for every node. Is this a SQL
Server backend? You might want to investigate returning form
information in a hierarchy by using XML from SQL and avoid round trips
to the database.
 
J

John Saunders

Tien said:
You can create more threads in your ASP.NET application in normal way,
and the thread still run even there is no active session :)

The thread may run, but it is invalid for such a thread to reference objects
from the Page, since the page may be gone by the time thread gets around to
running.
 
G

Guest

As others have mentioned it seems to be a design flaw more than anything else.
How would threading help you with your hierarchical nodes problems?
How would browser know when a certain thread is completed "database return"
running on the server.

I think the answer is caching, better indexing and better design rather than
threading. Also you might want to pre-process heavy duty tasks like building
hierarchical nodes structure on back-end, schedule a SQL job or something
like that.

Let me just reiterate that doing threading in a web application will get you
in more trouble than you trying to solve originally. I learned from my own
painful experience. Keep multithreading in Windows apps, and stick to
Response/Request HTTP way of doing things in ASP.NET.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top