public void Start() { _transport.MessageReceived += OnTransportMessageReceived; _transport.Start(); _receptionThread = BackgroundThread.Start(PendingReceivesProcessor); }
/// <summary> /// Shows the Window asynchronously on a background thread with the specified owner /// </summary> /// <param name="owner">The owner of the form, when the dialog is shown modally</param> /// <returns></returns> public void ShowAsynchronously(IWin32Window owner) { _failed = false; _createdEvent = new ManualResetEvent(false); _thread.Start(true, new object[] { owner }); _createdEvent.WaitOne(); }
public void Start() { var zmqVersion = ZmqUtil.GetVersion(); _logger.InfoFormat("Loaded ZMQ v{0}", zmqVersion.ToString(3)); if (zmqVersion.Major != 4) { throw new InvalidOperationException($"Expected ZMQ v4.*, loaded ZMQ v{zmqVersion.ToString(3)}"); } _isListening = true; _outboundSockets = new ConcurrentDictionary <PeerId, ZmqOutboundSocket>(); _outboundSocketActions = new BlockingCollection <OutboundSocketAction>(); _pendingDisconnects = new BlockingCollection <PendingDisconnect>(); _context = new ZmqContext(); var startSequenceState = new InboundProcStartSequenceState(); _inboundThread = BackgroundThread.Start(InboundProc, startSequenceState); _outboundThread = BackgroundThread.Start(OutboundProc); _disconnectThread = BackgroundThread.Start(DisconnectProc); startSequenceState.Wait(); _isRunning = true; }
public void Start() { var waitHandle = new ManualResetEvent(false); _inMemoryMessageMatcher.EnqueueWaitHandle(waitHandle); _cancellationTokenSource = new CancellationTokenSource(); _runThread = BackgroundThread.Start(RunProc, waitHandle); }
/// <summary> /// Starts a background thread that will receive messages for the connection /// </summary> public virtual void BeginReceiving() { if (this.IsReceiving) { return; } _disconnectOnStop = false; _stopEvent = new ManualResetEvent(false); _thread = new BackgroundThread(); // _thread.IsBackground = false; //_thread.AllowThreadAbortException = true; _thread.Run += new BackgroundThreadStartEventHandler(OnReadFromSocket); _thread.Start(true /* background thread */, new object[] {}); }
public void Start() { IsListening = true; _outboundSockets = new ConcurrentDictionary <PeerId, ZmqOutboundSocket>(); _outboundSocketActions = new BlockingCollection <OutboundSocketAction>(); _pendingDisconnects = new BlockingCollection <PendingDisconnect>(); _context = ZmqContext.Create(); var startSequenceState = new InboundProcStartSequenceState(); _inboundThread = BackgroundThread.Start(InboundProc, startSequenceState, null); _outboundThread = BackgroundThread.Start(OutboundProc); _disconnectThread = BackgroundThread.Start(DisconnectProc); startSequenceState.Wait(); }
/// <summary> /// Starts the server (Incoming connections will be accepted while the server is started) /// </summary> /// <param name="ep"></param> /// <returns></returns> public bool Start(IPEndPoint ep) { try { _thread = new BackgroundThread(); _thread.AllowThreadAbortException = true; _thread.Run += new BackgroundThreadStartEventHandler(OnThreadRun); _thread.Start(true, new object[] { ep }); return(true); } catch (Exception ex) { this.OnException(this, new ExceptionEventArgs(ex)); } return(false); }
private static void Initialize_impl(string config_file = null) { lock (s_storage_init_lock) { if (s_master_init_flag) { return; } TrinityC.Init(); if (config_file != null) { TrinityConfig.LoadConfig(config_file); } else { TrinityConfig.EnsureConfig(); } Log.Initialize(); _LoadGraphEngineExtensions(); _ScanForTSLStorageExtension(); _ScanForMemoryCloudExtension(); _ScanForStartupTasks(); s_master_init_flag = true; BackgroundThread.Start(); if (TrinityErrorCode.E_SUCCESS != StartEventLoop()) { throw new Exception("Cannot start worker thread pool"); } } try { Initialized(); } catch { //TODO log } }
/// <summary> /// Asyncronously begins a background thread which pings the address X number of times /// </summary> public void BeginPinging(string address, int timesToPing) { // if the thread is null reset it if (_thread == null) { // each instance of the engine will use a background thread to perform it's work _thread = new BackgroundThread(); _thread.Run += new BackgroundThreadStartEventHandler(OnThreadRun); _thread.Finished += new BackgroundThreadEventHandler(OnThreadFinished); _thread.AllowThreadAbortException = true; } // if the thread is not running if (!_thread.IsRunning) { // start it up _thread.Start(true, new object[] { address, timesToPing }); } }
/// <summary> /// Starts the server. Optionally enabling Asp.NET hosting if the host OS supports it. /// </summary> /// <param name="ep"></param> /// <param name="enableAspNetHosting"></param> /// <returns></returns> public bool Start(IPEndPoint ep, bool enableAspNetHosting) { try { _dispatcher = new HttpRequestDispatcher(enableAspNetHosting && this.CanOSSupportAspNet); _thread = new BackgroundThread(); _thread.Run += new BackgroundThreadStartEventHandler(OnThreadRun); _thread.Start(true, new object[] { ep }); _isStarted = true; EventManager.Raise <EventArgs>(this.ServerStarted, this, EventArgs.Empty); return(true); } catch (Exception ex) { this.OnException(this, new ExceptionEventArgs(ex)); } return(false); }
private static void Initialize_impl(string config_file = null) { lock (s_storage_init_lock) { if (s_master_init_flag) { return; } TrinityC.Init(); if (config_file != null) { TrinityConfig.LoadConfig(config_file); } else { TrinityConfig.EnsureConfig(); } Log.Initialize(); _LoadGraphEngineExtensions(); _ScanForTSLStorageExtension(); _ScanForMemoryCloudExtension(); _ScanForStartupTasks(); s_master_init_flag = true; BackgroundThread.Start(); } try { Initialized(); } catch { //TODO log } }
public void should_not_continue_execution_after_awaiting_a_send_in_the_MessageReceived_thread() { using (MessageId.PauseIdGeneration()) { var command = new FakeCommand(456); SetupPeersHandlingMessage <FakeCommand>(_peerUp); _bus.Start(); var task = _bus.Send(command); var commandCompleted = new MessageExecutionCompleted(MessageId.NextId(), 0, null); int backgroundThreadId = 0; BackgroundThread.Start(() => { backgroundThreadId = Thread.CurrentThread.ManagedThreadId; _transport.RaiseMessageReceived(commandCompleted.ToTransportMessage()); }); var getThreadIdTask = GetThreadIdAfterAwaitingCommandResult(task); getThreadIdTask.Result.ShouldNotEqual(backgroundThreadId); } }
/// <summary> /// Initializes Graph Engine. /// This method will be automatically called /// when the static constructor of `Global` /// is triggered. However, when the Graph Engine /// is uninitialized, one would have to manually /// call this again before using the local memory storage. /// </summary> public static void Initialize() { lock (s_storage_init_lock) { if (s_master_init_flag) { return; } _LoadGraphEngineExtensions(); _ScanForTSLStorageExtension(); _ScanForMemoryCloudExtension(); _ScanForStartupTasks(); s_master_init_flag = true; BackgroundThread.Start(); } try { Initialized(); } catch { //TODO log } }
static void Main(string[] args) { BackgroundThread bt = new BackgroundThread(plainOldWorkerFunction, plainOldCallbackFunction); bt.Start(1234); }
private void StartReceptionThread() { _receptionThread = BackgroundThread.Start(PendingReceivesDispatcher); }
public MainWindow() { InitializeComponent(); NotificationManager.Instance.Targets.Add(this); Closing += (sender, e) => NotificationManager.Instance.Targets.Remove(this); groupOpen = new TasksGroupControl("Open tasks"); groupPostponed = new TasksGroupControl("Postponed tasks"); groupClosed = new TasksGroupControl("Closed tasks"); groups.Add(groupOpen); groups.Add(groupPostponed); groups.Add(groupClosed); foreach (TasksGroupControl group in groups) { pnlGroups.Children.Add(group); group.OnTaskSelect += OnTaskSelect; group.OnTaskSelected += OnTaskSelected; } groupOpen.BackgroundSelector = new OpenTaskBackgroundSelector(); groupPostponed.BackgroundSelector = new OpenTaskBackgroundSelector(); groupClosed.BackgroundSelector = new TaskBackgroundSelector(); groupOpen.DateSelector = new DeadlineSelector(); groupPostponed.DateSelector = new DeadlineSelector(); groupClosed.DateSelector = new ClosedSelector(); groupOpen.ActivityVisibilitySelector = new SimpleBoolSelector(true); groupPostponed.ActivityVisibilitySelector = new SimpleBoolSelector(false); groupClosed.ActivityVisibilitySelector = new SimpleBoolSelector(false); groupOpen.GroupIconsSelector = new DeadlineIconsSelector(); groupPostponed.GroupIconsSelector = new DeadlineIconsSelector(); groupOpen.TaskDoubleClick += t => Command_EditTask(null, null); groupPostponed.TaskDoubleClick += t => Command_EditTask(null, null); groupClosed.TaskDoubleClick += t => Command_ShowTask(null, null); groupOpen.AddOrderSelector(x => x.Task.Deadline, false).AddOrderSelector(x => x.Task.Priority, true); groupPostponed.AddOrderSelector(x => x.Task.Deadline, false).AddOrderSelector(x => x.Task.Priority, true); groupClosed.AddOrderSelector(x => x.Task.Closed, true); groupOpen.OnTaskControlCreated += t => ActionsCollection.Instance.Add(new TaskControlAction(t)); groupPostponed.OnTaskControlCreated += t => ActionsCollection.Instance.Add(new TaskControlAction(t)); groupOpen.OnTaskControlRemove += t => ActionsCollection.Instance.Remove(ActionsCollection.Instance.Actions.OfType <TaskControlAction>().FirstOrDefault(x => x.TaskControl == t)); groupPostponed.OnTaskControlRemove += t => ActionsCollection.Instance.Remove(ActionsCollection.Instance.Actions.OfType <TaskControlAction>().FirstOrDefault(x => x.TaskControl == t)); groupOpen.Collapse(false); ActionsCollection.Instance.Add(new DeadlineIconsAction(groupOpen)); ActionsCollection.Instance.Add(new DeadlineIconsAction(groupPostponed)); ActionsCollection.Instance.Add(new TaskArchivingAction(groupClosed)); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) { foreach (Task task in repository.GetAll()) { switch (task.State) { case TaskState.Open: groupOpen.AddTask(task); ActionsCollection.Instance.Add(new TaskDeadlineAction(task)); break; case TaskState.Postponed: groupPostponed.AddTask(task); ActionsCollection.Instance.Add(new TaskDeadlineAction(task)); break; case TaskState.Closed: groupClosed.AddTask(task); break; } } } TemplatesAction templatesAction = new TemplatesAction(); templatesAction.TaskCreated += task => { if (task != null) { groupOpen.Dispatcher.Invoke(() => groupOpen.AddTask(task)); using (IRepository <Task, long> repository = PersistentFactory.GetContext().GetRepository <Task, long>()) repository.Add(task); StatsHelper.Update(StatsData.TaskCreated); StatsHelper.Update(StatsData.TaskCreatedFromTemplate); NotificationHelper.Notify(NotificationType.TaskCreatedFromTemplate, task.Name); ActionsCollection.Instance.Add(new TaskDeadlineAction(task)); } }; ActionsCollection.Instance.Add(templatesAction); ActionsCollection.Instance.Add(new LastRunAction()); backgroundThread.Start(); RefreshMenu(); Log.Debug($"{groups.Sum(x => x.Count)} tasks loaded", this); Log.Info("Main window opened", this); }
public Promise OpenForNewConnections() { isListening = true; listeningDeferred = Deferred.Create(); var startListeningDeferred = Deferred.Create(); BackgroundThread t = null; t = new BackgroundThread(() => { try { listener = new TcpListener(IPAddress.Any, port); listener.Start(); } catch (Exception ex) { startListeningDeferred.Reject(ex); return; } // we have started listening startListeningDeferred.Resolve(); try { while (isListening && t.IsExpired == false) { Socket socket; try { socket = listener.AcceptSocket(TimeSpan.FromSeconds(1)); if (t.IsExpired) { return; } } catch (TimeoutException) { continue; } var connection = new RemoteSocketConnection() { ClientId = (socket.RemoteEndPoint as IPEndPoint).Address.ToString() + ":" + (socket.RemoteEndPoint as IPEndPoint).Port, RemoteSocket = socket, MessageReceived = this.MessageReceived, }; this.OnDisposed(connection.Dispose); connection.Listen(); connections.Add(connection.ClientId, connection); ClientConnected.Fire(connection); } listener.Stop(); listeningDeferred.Resolve(); } catch (Exception ex) { listeningDeferred.Reject(ex); } finally { listeningDeferred = null; } }); this.OnDisposed(t.Dispose); t.Start(); return(startListeningDeferred.Promise); }