Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }