This sample allows you to highlight C# source code. Highlighting is based on http://hilite.me web service, which is called from a background job in a truly asynchronous way – neither controller, nor any other entity is waiting for a completion. Results are delivered via WebSockets using SignalR.

All the snippets are removed every day at 12:00 AM UTC.

// ~/Controllers/HomeController.cs

[HttpPost]
public ActionResult Create([Bind(Include = "SourceCode")] CodeSnippet snippet)
{
    try
    {
        if (ModelState.IsValid)
        {
            snippet.CreatedAt = DateTime.UtcNow;

            using (StackExchange.Profiling.MiniProfiler.StepStatic("Service call"))
            {
                snippet.HighlightedCode = HighlightSource(snippet.SourceCode);
                snippet.HighlightedAt = DateTime.UtcNow;
            }

            _db.CodeSnippets.Add(snippet);
            _db.SaveChanges();

            return RedirectToAction("Details", new { id = snippet.Id });
        }
    }
    catch (HttpRequestException)
    {
        ModelState.AddModelError("", "Highlighting service returned error. Try again later.");
    }

    return View(snippet);
}
Console.WriteLine("Hello, world!");