multithreading question

R

Rob

In order to show a loading page, I am attempting to call a function as
part of a new thread, my issue is that the function returns a boolean
if it is succesful since it also calls other functions,,

how can I start this function in its own thread, yet get back its true
or false to know it succeeded?

thanks in advance
r
 
S

Scott Allen

Hi Rob:

One way to do this would be to wrap the function in a delegate.
BeginInvoke will start the function on a background thread, EndInvoke
will allow you to harvest the results.

You'll want to test carefully. Using additional threads in a server
process might not always be a performance / scalability improvement.
 
R

Rutger Smit

Rob said:
In order to show a loading page, I am attempting to call a function as
part of a new thread, my issue is that the function returns a boolean
if it is succesful since it also calls other functions,,

how can I start this function in its own thread, yet get back its true
or false to know it succeeded?

thanks in advance
r

Rob Howard explained this thing at TechEd Europe 2004 in Amsterdam.
Don't know if Microsoft is happy with it, but you can download his ppt
and wmv here:

http://www.rutgersmit.com/misc/msdn/DEV310.ppt
http://www.rutgersmit.com/misc/msdn/DEV310.wmv (32 MB)

Those two items were published on the TechEd Europe 2004 post conference
DVD.


--

//Rutger

DoDotNet@KICKTHIS_Gmail.com
www.RutgerSmit.com
 
R

Rick Strahl [MVP]

Hi rob,

If you're firing off a new thread I suggest you fire off this thread onto a
method of an object that your main application thread holds. That way you
can set some sort of state that both share and access. IOW, the new thread
can update a property on the object that the main thread can check or read
at some later point in time.

As Scott mentioned though, you'll want to be real careful with threads on
the server - there are lifetime issues that are very uh funky. It's Ok if
you create a thread and run it in parallel with your ASPX page thread, but
it gets tricky when your thread outlasts the main ASPX thread.

Generally a 'loading...' type page is better done via some sort of
asynchronous request that keeps refreshing until the task is done. This way
the Web Server is not tied up with this process.

Regards,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 
R

Rob

Rick, since google takes a while to post this stuff, I went ahead and
funny enough came up with a solution to do a loading page which runs
the function in its own thread and checks session variable to see if
its done, and Now I read this!

is it really bad to do it this way, how can the function(which is in
its own thread) not be complete, if it sets the global variable when
its finished, how do I know about lifetime issues is there a way?

thanks for your thoughts
r
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top