I have not actually tried it and its compiled with GMail ;)
IHttpHandler.ProcessRequest(HttpContext c)
{
// register with data provider
provider.DataAvailable += DataAvailable;
while (true)
{
dataAvailable.WaitOne(); // with a timeout is probably better ...
FlushData( data);
}
}
// your class that provides whatever data you need to flush to the client
DataArg data;
// signals when data is available
AutoResetEvent dataAvailable = new AutoResetEvent( false);
void DataAvailable(object sender, DataArg e)
{
// keep ref to available data
// take notice that a race condition exists here!
// a solution could be disconnect from the provider and after flushing
// the data reconnect with the provider
data = e;
dataAvailable.Set();
}
HTH
// Ryan
On Jan 7, 2008 5:54 PM, Mark Fruhling <[EMAIL PROTECTED]> wrote:
> How can I put the initial thread to sleep and then have it awaken when
> the event fires?
>
> Ryan Heath wrote:
> > I guess your HttpHandler should *never* return and always wait for an
> event
> > to happen.
> >
> > IHttpHandler.ProcessRequest(HttpContext c)
> > {
> > while ( stayOpen)
> > {
> > WaitForEvent();
> > FlushDataToClient();
> > }
> > }
> >
> >
> > FWIW
> > I liked theory of the Comet pattern until I realised it doesn't scale.
> > A single server has a finite number of connections that should stay
> open.
> > A cluster of servers is not helpful since a client is bound to a single
> > server.
> > However, I think it is useful for a small number of clients.
> >
> > // Ryan
> >
> > On Jan 4, 2008 9:26 PM, Mark Fruhling <[EMAIL PROTECTED]> wrote:
> >
> >
> >> Marc,
> >>
> >> The "Comet Pattern" is exactly what I'm trying to do. My specific
> >> question is how to create the event mechanism on the web server. The
> >> only idea I've come up with is the polling of a server object. I was
> >> hoping someone might be able to point me in a more elegant direction.
> >>
> >>
> >>
> >> Marc Brooks wrote:
> >>
> >>>> I've created an ajax chat client and I am trying to avoid doing a
> http
> >>>>
> >> call
> >>
> >>>> every second to check on messages. I would like to call the web
> >>>>
> >> service and
> >>
> >>>> the following occur.
> >>>>
> >>>>
> >>> What you want is to apply the Comet pattern where you leave a "hung
> >>> open" request that gets pushed into by the server when new data is
> >>> available. Then the client immediately requests another connection
> >>> which is then hung-open until the next poll/trigger is available.
> >>>
> >>> See:
> >>> http://en.wikipedia.org/wiki/Comet_%28programming%29
> >>>
> >>>
> >>>
> >> ===================================
> >> This list is hosted by DevelopMentor(R) http://www.develop.com
> >>
> >> View archives and manage your subscription(s) at
> >> http://discuss.develop.com
> >>
> >>
> >
> > ===================================
> > This list is hosted by DevelopMentor(R) http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> http://discuss.develop.com
> >
> >
> >
>
> ===================================
> This list is hosted by DevelopMentor(R) http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com