Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do I write streamed output in NancyFX?
  2. public class HomeModule : NancyModule
  3. {
  4.     public HomeModule()
  5.     {
  6.         Get["/slow"] = _ => new SlowStreamResponse();
  7.     }
  8.  
  9.     private class SlowStreamResponse : Response
  10.     {
  11.         public SlowStreamResponse()
  12.         {
  13.             ContentType = "text/plain";
  14.             BufferOutput = false;
  15.             Contents = s => {
  16.                 byte[] bytes = Encoding.UTF8.GetBytes("Hello Worldn");
  17.                 for (int i = 0; i < 10; ++i)
  18.                 {
  19.                     s.Write(bytes, 0, bytes.Length);
  20.                     Thread.Sleep(500);
  21.                 }
  22.             };
  23.         }
  24.     }