Example #1
0
        private static void RunControlRunner(MainForm form, string[] args)
        {
            Console.WriteLine("Thread {0}", Thread.CurrentThread.Name);
            Console.WriteLine("InvokeRequired {0}", form.InvokeRequired);
            var uir = new ControlRunner(form, (ex) =>
            {
                Console.WriteLine(ex.Message);
                throw new Exception("Should be ignored");
            });
            var ior = new ThreadRunner("Runner");

            ior.Run(() =>
            {
                Console.WriteLine("InvokeRequired {0}", form.InvokeRequired);
                Console.WriteLine("Thread {0}", Thread.CurrentThread.Name);
                uir.Run(() => { throw new Exception("Should be catched"); });
                uir.Run(() =>
                {
                    Console.WriteLine("InvokeRequired {0}", form.InvokeRequired);
                    Console.WriteLine("Thread {0}", Thread.CurrentThread.Name);
                    Console.WriteLine("form.Text {0}", form.Text);
                    form.Close();
                });
            });
        }
 public void Setup(Control control, Action <bool, bool> connected, Action <string, string> log)
 {
     this.log       = log;
     this.connected = connected;
     this.uir       = new ControlRunner(control);
     this.ior       = new ThreadRunner("IO", IoException);
 }
 private void TerminalControl_Load(object sender, EventArgs e)
 {
     uir = new ControlRunner(this);
     ior = new ThreadRunner("IO", IoException, IoIdle, 50);
     RefreshSerials();
     EnableControls(true);
     UpdateReadline();
     timer.Enabled = true;
 }
 void ModbusControl_Load(object sender, EventArgs e)
 {
     uir = new ControlRunner(this);
     ior = new ThreadRunner("IO", (Exception ex) => {
         IoClose();
         uir.Run(() => Log("error", "Error: {0}", ex.Message));
     });
     RefreshSerials();
     EnableControls(true);
     timer.Enabled = pollCheckBox.Checked;
 }
        public void Dispose()
        {
            var ior = this.ior;

            if (ior == null)
            {
                return;
            }
            ior.Run(() => {
                Disposer.Dispose(master);
                master = null;
                uir    = null; //disposed
            });
            //fixes block on close while connected
            Task.Factory.StartNew(ior.Dispose);
        }
Example #6
0
 void MainFormLoad(object sender, EventArgs e)
 {
     uir = new ControlRunner(this);
     ior = new ThreadRunner("IO", (Exception ex) => {
         IoClose();
         uir.Run(() => {
             Log("error", "Error: {0}", ex.Message);
         });
     });
     Text = string.Format("{0} - {1} https://github.com/samuelventura/SharpMaster", Text, Exe.VersionString());
     WrapRunner.Try(() => {
         LoadSettings();
     });
     RefreshSerials();
     EnableControls(true);
 }