Exemplo n.º 1
0
        private void TaskEnded(Task task, string connectionId)
        {
            try
            {
                Console.WriteLine("Task with id {0} execution ended. status: {1}", task.Id, task.Status);
                MyHubConnector viewConnector = new MyHubConnector(m_MyHubContext, connectionId);

                if (task.IsFaulted)
                {
                    Console.WriteLine("Task execution failed.");
                    viewConnector.UpdateTaskStatus("error").Wait();
                }
                else
                {
                    viewConnector.UpdateTaskStatus("succsess").Wait();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception has been thrown when trying to notify on task end status");
            }
            finally
            {
                Task removedTask;
                bool isRemovedSuccsfully = m_AliveTasks.TryRemove(task.Id, out removedTask);
                if (!isRemovedSuccsfully)
                {
                    Console.WriteLine("an error occurred while trying to remove a task from the list");
                }
            }
        }
Exemplo n.º 2
0
        public int SendDataToClient([FromQuery] string connectionId)
        {
            Console.WriteLine("Sending data to connection id: {0}", connectionId);
            MyHubConnector viewConnector = new MyHubConnector(m_MyHubContext, connectionId);
            Task           task          = new Task(() =>
            {
                Thread.Sleep(10000);
                GeneralData generalData = new GeneralData
                {
                    SomeId     = Guid.NewGuid(),
                    SomeId2    = Guid.NewGuid(),
                    SomeId3    = Guid.NewGuid(),
                    SomeString = "Hello world"
                };
                Task sendGeneralDataTask = viewConnector.SendGeneralData(generalData);
                sendGeneralDataTask.Wait();
                Console.WriteLine("Done sending the current loaded trip plan");
            });

            m_TasksManager.AddTask(task, connectionId);
            return(0);
        }