Created
July 4, 2011 05:20
-
-
Save shiftkey/1062931 to your computer and use it in GitHub Desktop.
Faking a service call using Caliburn Micro Coroutines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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