示例#1
0
        protected MobileBase(IOutput output, BackgroundWorkerFactoryMethod backgroundWorkerFactory = null)
        {
            this.output = output;

            SMSProvider.SMSReciever += SMSMessenger.AddMessage;

            var workerFactory = backgroundWorkerFactory ?? new BackgroundWorkerFactoryMethod();

            Battery = new Battery();
            BackgroundWorkerBase discharge = workerFactory.CreateWorker(() => {
                while (true)
                {
                    Thread.Sleep(2500);
                    Battery.ChangeCharge(-Battery.CapacityWh / 100);
                }
            });

            discharge.Start();

            managebleChargeAction = new ManageableAction(new Action(() => {
                Thread.Sleep(1000);
                Battery.ChangeCharge(Charger == null ? 0f : (float)Math.Pow(Charger.ChargeCurrentMa, 2) * 0.00005f);
            }));
            BackgroundWorkerBase charge = workerFactory.CreateWorker(() => managebleChargeAction.ThreadStart());

            charge.Start();
        }
示例#2
0
        public FormCharging()
        {
            InitializeComponent();

            comboBoxFormatter.SelectedIndex = 0;
            comboBoxFormatter.Items.AddRange(formatterFactory.AvailableNames.ToArray());

            currentFormatter = formatterFactory.DefaultFormatter;

            mobile = new ModernMobile(output);
            mobile.SMSMessenger.MessageAdded += (message, isAdded) => {
                if (!phonesSet.Contains(message.Number))
                {
                    phonesSet.Add(message.Number);
                    Invoke(new Action(() => comboBoxPhone.Items.Add(message.Number)));
                }

                if (mobile.SMSMessenger.MessageHistory.Count > MAXIMUM_OUTPUT)
                {
                    List <Message> temp = mobile.SMSMessenger.MessageHistory;
                    temp.RemoveRange(0, messageHistoryCopy.Count - MAXIMUM_OUTPUT);
                    messageHistoryCopy = temp;
                }
                else
                {
                    messageHistoryCopy = mobile.SMSMessenger.MessageHistory;
                }

                try {
                    Invoke(new Action(RefreshListView));
                }
                catch (ObjectDisposedException) {}
                catch (InvalidOperationException) {}
            };

            int notMainThreadSmsCount = 1;
            BackgroundWorkerFactoryMethod workerFactory = new BackgroundWorkerFactoryMethod();

            manageableAction = new ManageableAction(new Action(() => {
                if (notMainThreadSmsCount == 1)
                {
                    Thread.Sleep(300);
                }

                mobile.ReceiveSMS($"SMS #{notMainThreadSmsCount++} NOT from Main thread.", "700");

                Thread.Sleep(1000);
            }));
            SMSBackgroundSender = workerFactory.CreateWorker(() => manageableAction.ThreadStart());
            SMSBackgroundSender.Start();

            UpdateChargeBar();
        }
示例#3
0
        private async Task <BoolResult> AttemptStartupAsync(Context context)
        {
            Tracer.Info(context, $"Starting database=[{_connectionString}]");
            if (_config.UseSharedConnection)
            {
                await _connection.OpenAsync();
            }

            await InitializeDatabaseAsync(context);
            await PostInitializeDatabaseAsync(context).IgnoreFailure();

            _backgroundWorker = CreateBackgroundWorker();
            _backgroundThread = new Thread(() => HandleBackgroundRequests(context.Logger));
            _backgroundThread.Start();

            StartupCompleted = true;

            return(BoolResult.Success);
        }