Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Created July 4, 2011 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiftkey/1062931 to your computer and use it in GitHub Desktop.
Save shiftkey/1062931 to your computer and use it in GitHub Desktop.
Faking a service call using Caliburn Micro Coroutines
using System;
using System.ComponentModel.Composition;
using System.Windows.Threading;
using Caliburn.Micro;
namespace CaliburnMicroSample.Services
{
[Export(typeof(ISessionService))]
public class SessionService : ISessionService
{
public IResult Save()
{
// TODO: set up result here
return new ServiceCallResult();
}
}
public class ServiceCallResult : IResult
{
private DispatcherTimer timer;
public ServiceCallResult()
{
timer = new DispatcherTimer();
}
public void Execute(ActionExecutionContext context)
{
timer.Interval = TimeSpan.FromSeconds(5);
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
if (Completed != null)
Completed(this, new ResultCompletionEventArgs());
}
public event EventHandler<ResultCompletionEventArgs> Completed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment