public static void Start(string[] args) { Arguments = args; var app = new ThreadedConcurrentApp(threadCount: 4, blockUntilNextEvent: true, priority: ThreadPriority.Normal); app.Start(); app.Spawn(new __app()); Await = () => app.AwaitCompletion(); Stop = () => app.Stop(); }
public static void Start( string localServer, string remoteServer, int threads = 2, IEnumerable <Assembly> assemblies = null, IEnumerable <string> classes = null) { var concurrentApp = new ThreadedConcurrentApp(new Dictionary <string, Func <IConcurrentApp, object[], IConcurrentObject> >()); var app = new DistributedApp(concurrentApp, localServer); Loader.FromAssemblies(app, assemblies, null, only: classes); app.Connect = _ => { var waiter = new ManualResetEvent(false); var errors = new List <Exception>(); int waitFor = 2; NetMQFunctions.StartServer(app, localServer, connected: ex => { if (ex != null) { errors.Add(ex); } if (--waitFor == 0) { waiter.Set(); } }); NetMQFunctions.StartClient(app, localServer, remoteServer, ex => { if (ex != null) { errors.Add(ex); } if (--waitFor == 0) { waiter.Set(); } }); waiter.WaitOne(); return(errors.Any() ? new AggregateException(errors) : null); }; app.Start(); }
public static void Start( string localServer, string remoteServer, int threads = 2, IEnumerable <Type> classes = null, IDictionary <Guid, IConcurrentObject> managedInstances = null) { var concurrentApp = new ThreadedConcurrentApp(new Dictionary <string, Func <IConcurrentApp, object[], IConcurrentObject> >()); var app = new DistributedApp(concurrentApp, localServer); if (classes != null) { foreach (var @class in classes) { Guid id; IConcurrentObject @object; app.RegisterClass(@class); if (isConcurrentSingleton(@class, out id, out @object)) { if (managedInstances != null) { managedInstances[id] = @object; } app.RegisterInstance(id, @object); } } } app.Connect = _ => { var waiter = new ManualResetEvent(false); var errors = new List <Exception>(); int waitFor = 2; NetMQFunctions.StartServer(app, localServer, connected: ex => { if (ex != null) { errors.Add(ex); } if (--waitFor == 0) { waiter.Set(); } }); NetMQFunctions.StartClient(app, localServer, remoteServer, ex => { if (ex != null) { errors.Add(ex); } if (--waitFor == 0) { waiter.Set(); } }); waiter.WaitOne(); return(errors.Any() ? new AggregateException(errors) : null); }; app.Start(); }