[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Spawn a thread inside a web service method causes serialization exception

(Alex Brown)

12/26/2002 3:30:00 AM

I am trying to spawn a thread inside of a web service method. It
compiles just fine, but when I try to test the service I get the
following exception:

"System.Threading.Thread cannot be serialized because it does not have
a default public constructor"

Obviously a thread is not serializable, but I'm not returning a
thread! Does every object used inside this function have to be
serializable? Is it possible that you just can't spawn a thread inside
a web service method? If anyone has tried this, I could use your help.

Thanks!
Alex Brown

Here is my function:

<WebMethod()> Public Function BeginOptimizing() As Boolean

Dim Solver As New SolverForm.Optimizer( _
LogPath, _
ConnectionStr, _
ScenarioID, _
AccountID, _
Guid _
)

Dim SolverThread As Thread
SolverThread = New Thread(AddressOf Solver.BeginOptimizing)
SolverThread.Name = "foo"
SolverThread.Start()
Application(SolverThread.Name) = SolverThread
Return True
End Function
2 Answers

Scott Seely

11/23/2002 5:43:00 AM

0

Why are you trying to store the thread in the ASP.Net Application
collection? I think I know what you are trying to do, but you should look
at TheadPool.QueueUserWorkItem and async server methods (Begin_WebMethodName
& End_WebMethodName).

--
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.


This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cp...

"Alex Brown" <alex@logic-tools.com> wrote in message
news:adb1b91d.0211221623.5c1e3b23@posting.google.com...
> I am trying to spawn a thread inside of a web service method. It
> compiles just fine, but when I try to test the service I get the
> following exception:
>
> "System.Threading.Thread cannot be serialized because it does not have
> a default public constructor"
>
> Obviously a thread is not serializable, but I'm not returning a
> thread! Does every object used inside this function have to be
> serializable? Is it possible that you just can't spawn a thread inside
> a web service method? If anyone has tried this, I could use your help.
>
> Thanks!
> Alex Brown
>
> Here is my function:
>
> <WebMethod()> Public Function BeginOptimizing() As Boolean
>
> Dim Solver As New SolverForm.Optimizer( _
> LogPath, _
> ConnectionStr, _
> ScenarioID, _
> AccountID, _
> Guid _
> )
>
> Dim SolverThread As Thread
> SolverThread = New Thread(AddressOf Solver.BeginOptimizing)
> SolverThread.Name = "foo"
> SolverThread.Start()
> Application(SolverThread.Name) = SolverThread
> Return True
> End Function


(Alex Brown)

12/26/2002 3:31:00 AM

0

I shouldn't have posted this question. My problem turned out to be in
a different function in my class (the stack trace for the runtime
exception didn't pinpoint the source of the problem). Thank you for
your advice and consideration - sorry to waste time with an errant
post.
-Alex Brown