Ask a Question related to ASP.NET Web Services, Design and Development.
-
wbarr@tin-man.co.uk #1
Web Service and Threads
What I'm trying to do is call a web service which then invokes a worker
thread. This thread should then handle any further lengthy processsing
freeing up the WebService to complete and terminiate.
To do this I'm using code similar
In the Client application I call
Public Sub InvokeWebService
Dim WS As New WS.Xfer
Try
Console.Write("Started")
Dim cb As AsyncCallback = New AsyncCallback(AddressOf MyCallback)
Dim ar As IAsyncResult = WS.BeginXfer(LogInf, cb, Nothing)
Catch e As Exception
Console.WriteLine("Exception Occured: " & e.ToString())
End Try
End Sub
Public Sub MyCallback(ByVal ar As IAsyncResult)
Dim WS As WS.Xfer = DirectCast(ar.AsyncState, WS.Xfer)
Dim ReturnValue As String = WS.EndXfer(ar)
Console.Write("Finished")
End Sub
Then in the web service I have the following
<WebMethod(Description:="Do Lengthy Processing.")> _
Public Function Xfer(ByVal newLogInfo As LogInfo) As Boolean
Return DoSomething(newLogInfo)
End Function
Private Function DoSomething(ByVal LogInfo As LogInfo) As Boolean
Dim st As New ThrdState
st.mLogInfo = LogInfo
...
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf MyRefresh),
st)
...
Return True
End Function
' CALLBACK
Private Sub MyRefresh(ByVal state As Object)
Dim st As ThrdState = CType(state, ThrdState)
Dim LogInfo As LogInfo = st.mLogInfo
...
Do lengthy Processing here
...
End Sub
The problem is that when the web service completes the spawned thread
terminiates. What I want is for the Web Service to complete and the
spawned thread continue processing in the background. The Web Service
doesn't care what now happens in the spawned thread.
Any help greatly appreciated
wbarr@tin-man.co.uk Guest
-
Debugging Threads
Hi all, people have problems debugging threads. What do others think about, setting abort_on_exception to true if ruby's command line option -d... -
Need a bit of help with threads programming
Hi all, I need a subroutine that reads the next line in an open file. Ordinarily this would be a trivial subroutine... you just read a line off... -
Threads troubles
Hi, I am trying to write a multiuser server (for games, chat, etc) in Perl. In time, this program might have to service >500 users... -
Saving Threads
Is there a way to save all the messages in a thread of do you have to save them from the forum one at a time? Dick -- Using M2, Opera's... -
Using threads to obtain a value
I have a few classes that all try to obtain the same data as each other using different methods. Each one takes around 5 seconds to get the data,... -
Brock Allen #2
Re: Web Service and Threads
You should look into making your WebService an Async Handler:
[url]http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/default.aspx[/url]
-Brock
DevelopMentor
[url]http://staff.develop.com/ballen[/url]
> What I'm trying to do is call a web service which then invokes a
> worker thread. This thread should then handle any further lengthy
> processsing freeing up the WebService to complete and terminiate.
>
> To do this I'm using code similar
>
> In the Client application I call
>
> Public Sub InvokeWebService
> Dim WS As New WS.Xfer
> Try
> Console.Write("Started")
> Dim cb As AsyncCallback = New AsyncCallback(AddressOf MyCallback)
> Dim ar As IAsyncResult = WS.BeginXfer(LogInf, cb, Nothing)
> Catch e As Exception
> Console.WriteLine("Exception Occured: " & e.ToString())
> End Try
> End Sub
> Public Sub MyCallback(ByVal ar As IAsyncResult)
> Dim WS As WS.Xfer = DirectCast(ar.AsyncState, WS.Xfer)
> Dim ReturnValue As String = WS.EndXfer(ar)
> Console.Write("Finished")
> End Sub
> Then in the web service I have the following
>
> <WebMethod(Description:="Do Lengthy Processing.")> _
> Public Function Xfer(ByVal newLogInfo As LogInfo) As Boolean
> Return DoSomething(newLogInfo)
> End Function
> Private Function DoSomething(ByVal LogInfo As LogInfo) As Boolean
> Dim st As New ThrdState
> st.mLogInfo = LogInfo
> ...
>
> ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf MyRefresh),
> st)
>
> ...
>
> Return True
> End Function
> ' CALLBACK
> Private Sub MyRefresh(ByVal state As Object)
> Dim st As ThrdState = CType(state, ThrdState)
> Dim LogInfo As LogInfo = st.mLogInfo
> ...
> Do lengthy Processing here
> ...
> End Sub
> The problem is that when the web service completes the spawned thread
> terminiates. What I want is for the Web Service to complete and the
> spawned thread continue processing in the background. The Web Service
> doesn't care what now happens in the spawned thread.
>
> Any help greatly appreciated
>
Brock Allen Guest



Reply With Quote

