Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
public static class Preform
{
public static SomthingBuilder ThisAction(Action action)
{
return new SomthingBuilder(action);
}
}
public class SomthingBuilder
{
private delegate void Now();
private readonly Action action;
public SomthingBuilder(Action action)
{
this.action = action;
}
public void Against(ISynchronizeInvoke control)
{
if (control.InvokeRequired)
{
control.Invoke(Do.This(action), null);
}
else
{
action();
}
}
private class Do
{
private readonly Action action;
public static Now This(Action action)
{
return new Do(action).execute;
}
private Do(Action action)
{
this.action = action;
}
private void execute()
{
action();
}
}
}
public interface ICommandExecutor
{
void Execute(Action action);
void Execute(Func<Action> action);
}
public class AsynchronousExecutor : ICommandExecutor
{
private readonly SynchronizationContext synchronizationContext;
public AsynchronousExecutor(SynchronizationContext synchronizationContext)
{
this.synchronizationContext = synchronizationContext;
}
[color green]//useful for operations that will not have an impact on the GUI. one-way operations[/color]
public void Execute(Action action)
{
ThreadPool.QueueUserWorkItem(item => action());
}
[color green]//do the bulk of the work in the background, then marshal the result back to the UI thread.[/color]
public void Execute(Func<Action> action)
{
ThreadPool.QueueUserWorkItem(item =>
{
var continuation = action();
synchronizationContext.Send(callBack => continuation(), null);
});
}
}