multithreading question

  • Thread starter Thread starter Rob
  • Start date Start date
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
 
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.
 
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
 
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/
 
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
 
Back
Top