O
OpticTygre
I have a class which represents an HTTPListener (call this
"aMessage"). The class accepts http requests, and responds to those
requests accordingly using simple code copied from the MSDN. What I
need to do however, is something that I can't seem to find in the
documentation.
My ProcessRequest subroutine needs to raise an event to its parent
application, then wait until the parent application returns a response
(through a public subroutine in aMessage), then unblock the
ProcessRequest subroutine and send the response.
I have accomplished this through shared variables (one representing a
response string, and the other representing a boolean that signals a
respose has been returned and the thread can continue processing) and
a very archaic polling routine, and I'm curious if there are better
ways to handle this type of situation. I'm sure there are, I just
don't know where to look.
If anyone could suggest some documentation, or - even better - sample
code that could accomplish this, it would be very helpful. Below is
some pseudo-code to show what I'm trying to do.
-----Schnipp-----
Private Shared m_IsResponseReady As Boolean = False
Private Shared m_ResponseString As String = String.Empty
Protected Overrides Sub ProcessRequest(ByVal Context As
System.Net.HttpListenerContext)
'Here goes some code to get the request from the Context object
'Raise an event passing the request string
RaiseEvent OnRequestReceived(strRequest)
'Here is where I want to lock the thread until a response is
received. Right now, I just use a
'polling mechanism checking the m_IsResponseReady boolean
Do While Not m_IsResponseReady
Thread.Sleep(500)
Loop
'Now that I have a request, I want to continue processing -
returning the response to the Context object.
End Sub
Public Sub SetResponse(ByVal Response as String)
m_ResponseString = Response
m_IsResponseReady = True
End Sub
-----Schnapp-----
Thanks, and happy new year!
-Jason
"aMessage"). The class accepts http requests, and responds to those
requests accordingly using simple code copied from the MSDN. What I
need to do however, is something that I can't seem to find in the
documentation.
My ProcessRequest subroutine needs to raise an event to its parent
application, then wait until the parent application returns a response
(through a public subroutine in aMessage), then unblock the
ProcessRequest subroutine and send the response.
I have accomplished this through shared variables (one representing a
response string, and the other representing a boolean that signals a
respose has been returned and the thread can continue processing) and
a very archaic polling routine, and I'm curious if there are better
ways to handle this type of situation. I'm sure there are, I just
don't know where to look.
If anyone could suggest some documentation, or - even better - sample
code that could accomplish this, it would be very helpful. Below is
some pseudo-code to show what I'm trying to do.
-----Schnipp-----
Private Shared m_IsResponseReady As Boolean = False
Private Shared m_ResponseString As String = String.Empty
Protected Overrides Sub ProcessRequest(ByVal Context As
System.Net.HttpListenerContext)
'Here goes some code to get the request from the Context object
'Raise an event passing the request string
RaiseEvent OnRequestReceived(strRequest)
'Here is where I want to lock the thread until a response is
received. Right now, I just use a
'polling mechanism checking the m_IsResponseReady boolean
Do While Not m_IsResponseReady
Thread.Sleep(500)
Loop
'Now that I have a request, I want to continue processing -
returning the response to the Context object.
End Sub
Public Sub SetResponse(ByVal Response as String)
m_ResponseString = Response
m_IsResponseReady = True
End Sub
-----Schnapp-----
Thanks, and happy new year!
-Jason