Ejemplo n.º 1
0
 public void WriteLine(string text)
 {
     if (ConsoleTextBox.InvokeRequired)
     {
         var del = new SafeCallTextDelegate(WriteLine);
         ConsoleTextBox.Invoke(del, text);
     }
     else
     {
         this.ConsoleTextBox.AppendText("[" + GetTimestamp() + "] " + text + Environment.NewLine);
         Console.WriteLine(text);
     }
 }
Ejemplo n.º 2
0
        protected void WriteTextSafe(Label label, string text)
        {
            if (label is null)
            {
                throw new ArgumentNullException(nameof(label));
            }

            if (label.InvokeRequired)
            {
                var d = new SafeCallTextDelegate(WriteTextSafe);
                label.Invoke(d, label, text);
            }
            else
            {
                label.Text = text;
            }
        }
Ejemplo n.º 3
0
        private void SetNotifyIconText(string text)
        {
            if (this.InvokeRequired)
            {
                var del = new SafeCallTextDelegate(SetNotifyIconText);
                this.Invoke(del, text);
            }
            else
            {
                // NotifyIcon.Text is limited to 64 char by a Windows API limitation, this gets around it using System.Reflection.
                if (text.Length >= 128)
                {
                    text = text.Substring(0, 127);
                }

                Type         t      = typeof(NotifyIcon);
                BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance;
                t.GetField("text", hidden).SetValue(this.notifyIcon, text);
                if ((bool)t.GetField("added", hidden).GetValue(this.notifyIcon))
                {
                    t.GetMethod("UpdateIcon", hidden).Invoke(this.notifyIcon, new object[] { true });
                }
            }
        }