Invoke() public method

public Invoke ( Delegate method ) : object
method System.Delegate
return object
Example #1
1
 public static void BeginInvokeInControlThread(Control c, MethodInvoker code)
 {
     //c.BeginInvoke(code);
     if (c.InvokeRequired)
         c.BeginInvoke(code);
     else
         c.Invoke(code);
 }
        public delegate void UpdateTaskList(TaskInfo step);//声明一个更新主线程的委托

        //绑定工作人员卡和内镜卡
        public void AddTaskList(TaskInfo info)
        {
            try
            {
                EXListView iTaskList = TaskList[info.Group];
                if (iTaskList.InvokeRequired)
                {
                    UpdateTaskList updatedelegate = new UpdateTaskList(AddTaskList);
                    ParentForm.Invoke(updatedelegate, new object[] { info });
                }
                else
                {
                    iTaskList.BeginUpdate();

                    //movie
                    EXListViewItem item     = new EXListViewItem(info.Card);
                    string         cardname = "";
                    string         workName = info.CleanWorker;
                    if (Cardlist.ContainsKey(info.Card))
                    {
                        cardname = Cardlist[info.Card];
                    }
                    if (Cardlist.ContainsKey(info.CleanWorker))
                    {
                        workName = Cardlist[info.CleanWorker];
                    }
                    item.SubItems.Add(cardname);
                    item.SubItems.Add(workName);
                    item.SubItems.Add(info.errorInfo);
                    for (int i = 4; i < iTaskList.Columns.Count; i++)
                    {
                        EXControlListViewSubItem cs = new EXControlListViewSubItem();
                        SkinProgressBar          b  = new SkinProgressBar();
                        b.TextFormat = SkinProgressBar.TxtFormat.None;
                        b.Tag        = item;
                        b.Minimum    = 0;
                        b.Maximum    = 100;
                        b.Step       = 1;
                        item.SubItems.Add(cs);
                        iTaskList.AddControlToSubItem(b, cs);
                    }

                    iTaskList.Items.Add(item);

                    EXControlListViewSubItem subitem = item.SubItems[info.Step + 3] as EXControlListViewSubItem;
                    SkinProgressBar          p       = subitem.MyControl as SkinProgressBar;
                    p.Maximum = info.Time * 10;
                    Thread th = new Thread(new ParameterizedThreadStart(UpdateProgressBarMethod));
                    th.IsBackground = true;
                    th.Start(p);

                    iTaskList.EndUpdate();
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(Exception), ex);
            }
        }
Example #3
0
 void Run()
 {
     System.Windows.Forms.Control tmp = Sender as System.Windows.Forms.Control;
     try
     {
         Command(Sender, this, Parameters);
         if (OnAsyncStateChangeEventHandler != null)
         {
             if (tmp != null && tmp.InvokeRequired)
             {
                 tmp.BeginInvoke(OnAsyncStateChangeEventHandler, Sender, this, Parameters, AsyncState.Finish, null);
             }
             else
             {
                 OnAsyncStateChangeEventHandler(Sender, this, Parameters, AsyncState.Finish, null);
             }
         }
     }
     catch (Exception ex)
     {
         if (OnError == null)
         {
             if (tmp != null && tmp.InvokeRequired)
             {
                 tmp.Invoke(new ErrorEventHandler(ShowError), Sender, ex);
             }
             else
             {
                 ShowError(Sender, ex);
             }
         }
         else
         {
             if (tmp != null && tmp.InvokeRequired)
             {
                 tmp.Invoke(new ErrorEventHandler(OnError), Sender, ex);
             }
             else
             {
                 OnError(Sender, ex);
             }
         }
         if (OnAsyncStateChangeEventHandler != null)
         {
             if (tmp != null && tmp.InvokeRequired)
             {
                 tmp.BeginInvoke(OnAsyncStateChangeEventHandler, Sender, this, Parameters, AsyncState.Finish, null);
             }
             else
             {
                 OnAsyncStateChangeEventHandler(Sender, this, Parameters, AsyncState.Finish, null);
             }
         }
     }
     finally
     {
         Done.Set();
     }
 }
Example #4
0
            public void doing()
            {
                try
                {
                    int             eId  = 99;
                    string          eMsg = "";
                    IBLL.IClientBLL bll  = new BLL.ClientBLL();
                    //上传销售出库单
                    decimal count = Conv.ToDecimal(bll.GetNoUpLoadSaleCount());
                    for (var i = 0; i < count / 100; i++)
                    {
                        bll.UpLoadSale(out eId, out eMsg);
                        if (eId == 0)
                        {
                            int temp_i = (int)count;
                            if (count > 100)
                            {
                                temp_i = (i + 1) * 100;
                            }
                            mainThreadCon.Invoke(deleg, 99, "销售出库单上传完成: " + temp_i);
                        }
                        else
                        {
                            throw new Exception("销售出库单上传异常:" + eMsg);
                            //mainThreadCon.Invoke(deleg, 99, eMsg);
                        }
                    }

                    //上传采购入库单
                    count = Conv.ToDecimal(bll.GetNoUpLoadInOutCount());
                    for (var i = 0; i < count / 100; i++)
                    {
                        bll.UpLoadInOut(out eId, out eMsg);
                        if (eId == 0)
                        {
                            int temp_i = (int)count;
                            if (count > 100)
                            {
                                temp_i = (i + 1) * 100;
                            }
                            mainThreadCon.Invoke(deleg, 99, "采购入库单上传完成: " + temp_i);
                        }
                        else
                        {
                            throw new Exception("销售出库单上传异常:" + eMsg);
                            //mainThreadCon.Invoke(deleg, 99, eMsg);
                        }
                    }

                    mainThreadCon.Invoke(deleg, 0, "");
                }
                catch (Exception ex)
                {
                    mainThreadCon.Invoke(deleg, -1, ex.GetMessage());
                    Log.writeLog("frmUpload ->MyTh.doing()", ex.ToString(), null);
                }
            }
Example #5
0
 public void InvokeCallMethod(Object objTarget, string NameMethod, object[] objParams)
 {
     if (m_TargetForm != null)
     {
         m_TargetForm.Invoke(this.m_CallMethod,
                             new Object[]
         {
             objTarget,
             NameMethod,
             objParams
         }
                             );
     }
 }
Example #6
0
 /// <summary>
 /// The invoke on main thread.
 /// </summary>
 /// <param name="control">
 /// The control.
 /// </param>
 /// <param name="act">
 /// The act.
 /// </param>
 public static void InvokeOnMainThread(this System.Windows.Forms.Control control, Action act)
 {
     if (control.IsHandleCreated)
     {
         control.Invoke(new MethodInvoker(act), null);
     }
 }
 public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
 {
     if (control.InvokeRequired) control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe),
          new object[] { control, propertyName, propertyValue });
     else control.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.SetProperty, null, control,
         new object[] { propertyValue });
 }
    public static object Invoke(System.Windows.Forms.Control obj, string methodName, params object[] paramValues)
    {
        Delegate del = null;
        string   key = obj.GetType().Name + "." + methodName;
        Type     tp;

        lock (methodLookup) {
            if (methodLookup.Contains(key))
            {
                tp = (Type)methodLookup[key];
            }
            else
            {
                Type[] paramList = new Type[obj.GetType().GetMethod(methodName).GetParameters().Length];
                int    n         = 0;

                foreach (ParameterInfo pi in obj.GetType().GetMethod(methodName).GetParameters())
                {
                    paramList[n++] = pi.ParameterType;
                }
                TypeBuilder        typeB = builder.DefineType("Del_" + obj.GetType().Name + "_" + methodName, TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.Public | TypeAttributes.Sealed, typeof(MulticastDelegate), PackingSize.Unspecified);
                ConstructorBuilder conB  = typeB.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[] { typeof(object), typeof(IntPtr) });
                conB.SetImplementationFlags(MethodImplAttributes.Runtime);
                MethodBuilder mb = typeB.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, obj.GetType().GetMethod(methodName).ReturnType, paramList);
                mb.SetImplementationFlags(MethodImplAttributes.Runtime);
                tp = typeB.CreateType();
                methodLookup.Add(key, tp);
            }
        }

        del = MulticastDelegate.CreateDelegate(tp, obj, methodName);
        return(obj.Invoke(del, paramValues));
    }
Example #9
0
 public static void InvokeIfRequired(Control c, VoidDelegate d)
 {
     if (c.InvokeRequired)
         c.Invoke(d);
     else
         d.Invoke();
 }
Example #10
0
 public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
 {
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (control.InvokeRequired)
     {
         if (control.IsHandleCreated)
         {
             try
             {
                 control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
             }
             catch { }
         }
     }
     else
     {
         if (!control.IsDisposed)
         {
             try
             {
                 control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
             }
             catch { }
         }
     }
 }
Example #11
0
 public static void SetEnabled(Control control, bool value)
 {
     if (control.InvokeRequired)
         control.Invoke(new SetEnabledDelegate(SetEnabled), control, value);
     else
         control.Enabled = value;
 }
Example #12
0
 public static void ResetText(Control control)
 {
     if (control.InvokeRequired)
         control.Invoke(new ResetTextDelegate(ResetText), control);
     else
         control.ResetText();
 }
Example #13
0
 public static void Hide(Control control)
 {
     if (control.InvokeRequired)
         control.Invoke(new ShowHideDelegate(Hide), control);
     else
         control.Hide();
 }
Example #14
0
 public void InvokeOnUiThread(Control control, Action<Control> action)
 {
     if(control.InvokeRequired)
     {
         control.Invoke(action);
     }
 }
Example #15
0
        /// <summary>
        /// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread.
        /// No action will be performed if the control doesn't have a valid handle or the control is Disposed/Disposing.
        /// </summary>
        /// <param name="control">the control for which the update is required</param>
        /// <param name="action">action to be performed on the control</param>
        public static void InvokeOnUiThreadIfRequired(this System.Windows.Forms.Control control, Action action)
        {
            try
            {
                //See https://stackoverflow.com/questions/1874728/avoid-calling-invoke-when-the-control-is-disposed
                //for background and some guidance when implementing your own version.
                //No action
                if (control.Disposing || control.IsDisposed || !control.IsHandleCreated)
                {
                    return;
                }

                if (control.InvokeRequired)
                {
                    control.Invoke((Action)(() =>
                    {
                        //No action
                        if (control.Disposing || control.IsDisposed || !control.IsHandleCreated)
                        {
                            return;
                        }

                        action();
                    }));
                }
                else
                {
                    action.Invoke();
                }
            }
            catch (Exception)
            {
            }
        }
        public static void DrawAnimation(this System.Windows.Forms.Control control, Func <Boolean> doEffect, Int32 interval = 10)
        {
            Action action = () =>
            {
                Timer effectTimer = new Timer();
                effectTimer.Interval = interval;
                effectTimer.Tick    += (s, e) =>
                {
                    Timer timer = s as Timer;
                    timer.Enabled = false;
                    try
                    {
                        if (doEffect != null && doEffect())
                        {
                            control.Invalidate();
                            timer.Enabled = true;
                        }
                        else
                        {
                            timer.Dispose();
                        }
                    }
                    catch
                    {
                        timer.Dispose();
                    }
                };
            };

            control.Invoke(action);
        }
Example #17
0
 public static void SetText(Control control, string text)
 {
     if (control.InvokeRequired)
         control.Invoke(new SetTextDelegate(SetText), control, text);
     else
         control.Text = text;
 }
Example #18
0
        public static object Get(Control control, object noncontrol, string propertyName)
        {
            if (control != null && !string.IsNullOrEmpty(propertyName))
                if (control.InvokeRequired)
                    return control.Invoke(new PropertyGetInvoker(Get),
                        control,
                        noncontrol,
                        propertyName
                        );
                else
                {
                    PropertyInfo pi = GetPropertyInfo(control, noncontrol, propertyName);
                    object invokee = (noncontrol == null) ? control : noncontrol;

                    if (pi != null)
                        if (pi.CanRead)
                            return pi.GetValue(invokee, null);
                        else
                            throw new Exception(
                                string.Format(
                                "{0}.{1} is a write-only property.",
                                invokee.GetType().ToString(),
                                propertyName
                                ));

                    return null;
                }
            else
                throw new ArgumentNullException("Invalid argument.");
        }
Example #19
0
            static private void ListenHandler()
            {
                var myIP        = Communication.GetLocalIP();
                var epLocal     = new System.Net.IPEndPoint(myIP, TCPPort);
                var tcpListener = new System.Net.Sockets.TcpListener(epLocal);

                tcpListener.Start();

                while (IsListening)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (tcpListener.Pending())
                    {
                        var tcpClient = tcpListener.AcceptTcpClient();
                        var netStream = tcpClient.GetStream();
                        var buffer    = new byte[1024];
                        if (!netStream.DataAvailable)
                        {
                            continue;
                        }

                        List <byte> bufferTotal = new List <byte>();
                        while (netStream.DataAvailable)
                        {
                            netStream.Read(buffer, 0, 1024);
                            bufferTotal.AddRange(buffer);
                        }
                        tcpClient.Close();
                        netStream.Close();
                        var receive = System.Text.Encoding.UTF8.GetString(bufferTotal.ToArray());
                        Owner.Invoke(DgGetMsg, receive);
                    }
                }
                tcpListener.Stop();
            }
Example #20
0
        public void WriteLine(int i, string text, bool Line)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            System.Windows.Forms.Control theTextBox = this.Dashboard.Controls.Find(textBoxPrefix + i, false)[0];
            string InputText = text + ((Line) ? System.Environment.NewLine : "");

            if (theTextBox.InvokeRequired)
            {
                StringArgReturningVoidDelegate d = new StringArgReturningVoidDelegate(WriteLine);
                theTextBox.Invoke(d, new object[] { i, text, Line });
            }
            else
            {
                if (!Line)
                {
                    try
                    {
                        ((TextBox)theTextBox).Text = ((TextBox)theTextBox).Text.Remove(((TextBox)theTextBox).Text.LastIndexOf(Environment.NewLine));
                        ((TextBox)theTextBox).AppendText(Environment.NewLine);
                    }
                    catch (ArgumentOutOfRangeException)
                    {}
                }

                ((TextBox)theTextBox).AppendText(InputText);
                //((TextBox)theTextBox).SelectionStart = theTextBox.Text.Length;
            }
        }
Example #21
0
 private Thread GetControlOwnerThread(Control ctrl)
 {
     if (ctrl.InvokeRequired)
         return (Thread)ctrl.Invoke(new Func<Thread>(() => GetControlOwnerThread(ctrl)));
     else
         return System.Threading.Thread.CurrentThread;
 }
Example #22
0
 private void EnableControl(Control control)
 {
     control.Invoke(new Action(() =>
     {
         control.Enabled = true;
     }));
 }
Example #23
0
        /// <summary>
        /// Helper method to determin if invoke required, if so will rerun method on correct thread.
        /// if not do nothing. From: http://stackoverflow.com/a/26506378/457880
        /// </summary>
        /// <param name="c">Control that might require invoking</param>
        /// <param name="a">action to preform on control thread if so.</param>
        /// <returns>true if invoke required</returns>
        public bool ControlInvokeRequired(Control c, Action a)
        {
            if (c.InvokeRequired) c.Invoke(new MethodInvoker(delegate { a(); }));
            else return false;

            return true;
        }
Example #24
0
 public static void InvokeIfNecessary(Control control, MethodInvoker action)
 {
     if (control.InvokeRequired)
         control.Invoke(action);
     else
         action();
 }
Example #25
0
 public static void add_text(Control c, object s)
 {
     if (c.InvokeRequired)
         c.Invoke(new Action<Control, object>(add_text), new object[] { c, s });
     else
         c.Text += s.ToString();
 }
        /// <summary>
        /// Signals the thread to exit and waits until it does so
        /// </summary>
        public void Exit()
        {
            Debug.Assert(!m_stopped, "Already stopped");
            m_stopped = true;

            if (SystemThread != null)
            {
                // TODO: OP! Should be done better
                try
                {
                    if (!m_form.IsDisposed)
                    {
                        m_form.Invoke(new Action(OnExit));
                    }
                }
                catch
                {
                    // Racing condition, form can be disposed after check and before Invoke
                }

                // TODO: OP! Should be done better
                if (Thread.CurrentThread != SystemThread)
                {
                    SystemThread.Join();
                }
            }
            else
            {
                UnloadContent();
                MyRenderProxy.DisposeDevice();
            }
        }
Example #27
0
        /// <summary>
        /// Get a property value on the control thread-safely.
        /// </summary>
        /// <param name="control">Control on which to GET the property value</param>
        /// <param name="propertyName">Property name</param>
        /// <return>Property value</return>
        public static object GetPropertyValue(Control control, string propertyName)
        {
            if (control != null && !string.IsNullOrEmpty(propertyName))
            {
                if (control.InvokeRequired)
                {
                    return control.Invoke(new PropertyGetInvoker(GetPropertyValue),
                                          control, propertyName);
                }
                else
                {
                    PropertyInfo propertyInfo = GetProperty(control, propertyName);
                    if (propertyInfo != null)
                    {
                        if (propertyInfo.CanRead)
                        {
                            return propertyInfo.GetValue(control, null);
                        }
                        else
                        {
                            throw new Exception(control.GetType().ToString() + "." + propertyName +
                                                " is write-only property.");
                        }
                    }

                    return null;
                }
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
 /// <summary>
 /// Metod för att aktivera eller inaktiver en kontroll på ett trådsäkert sätt.
 /// </summary>
 /// <param name="control"></param>
 /// <param name="enabled"></param>
 public void SetControlEnabled(Control control, bool enabled)
 {
     if (control.InvokeRequired) {
         control.Invoke(new SetControlEnabledCallback(SetControlEnabled), new object[] {control, enabled});
     } else {
         control.Enabled = enabled;
     }
 }
Example #29
0
 private void EnableControl(Control control, bool enable)
 {
     if (control.InvokeRequired)
         control.Invoke((MethodInvoker)
                        delegate { EnableControl(control, enable); });
     else
         control.Enabled = enable;
 }
Example #30
0
 /// <summary>
 /// SafeThread call of ShowDialog
 /// </summary>
 /// <param name="pOwner"></param>
 private void showDlgTS(Control pOwner) {
   if ((pOwner != null) && pOwner.InvokeRequired) {
     try {
       pOwner.Invoke(new Action<Control>(showDlgTS), new Object[] { pOwner });
     } catch (ObjectDisposedException) { }
   } else {
     this.ShowDialog(pOwner);
   }
 }
Example #31
0
 public static void InvokeInControlThread(Control c, MethodInvoker code)
 {
     if (c.InvokeRequired)
     {
         c.Invoke(code);
         return;
     }
     code.Invoke();
 }
Example #32
0
 private static async Task DispatchStartAsync(Control control, Bitmap bitmap, byte []buffer)
 {
    
     control.Invoke(new Action(() =>
     {
         ProcessStart(bitmap, buffer);
         control.Refresh();
     }));
 }
Example #33
0
 /// <summary>
 /// Threadsave Text Property setter
 /// </summary>
 /// <param name="control"></param>
 /// <param name="text"></param>
 public static void SetText(Control control, string text)
 {
     if(control.InvokeRequired) {
         SetTextCallback d = new SetTextCallback(SetText);
         control.Invoke(d, new object[] { control, text });
     } else {
         control.Text = text;
     }
 }
Example #34
0
 /// <summary>
 /// Ensure code is run on the UI thread.
 /// </summary>
 internal static void UIThread(Control form, MethodInvoker code)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(code);
         return;
     }
     code.Invoke();
 }
Example #35
0
 public static void UIThread(this System.Windows.Forms.Control form, MethodInvoker code)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(code);
         return;
     }
     code.Invoke();
 }
Example #36
0
        public static void SafeInvoke(Control ctr, Action action)
        {
            if (ctr == null || ctr.IsDisposed)
                return;

            if (ctr.InvokeRequired)
                ctr.Invoke(action);
            else
                action();
        }
Example #37
0
    /// <summary>
    /// A thread safe version to receive the <see cref="Control.Handle"/>
    /// property of the control.
    /// </summary>
    /// <param name="control">The <see cref="Control"/> to retreive the handle for.</param>
    /// <returns>An <see cref="IntPtr"/> with the handle of the control.</returns>
    public static IntPtr GetHandle(Control control)
    {
      if (control.InvokeRequired)
      {
        var d = new GetHandleCallback(GetHandle);
        return (IntPtr)control.Invoke(d, control);
      }

      return control.Handle;
    }
Example #38
0
 public static void ShowErrorDialog(Control owner, string message, Exception exception) {
   if (owner == null) throw new ArgumentNullException("owner");
   if (owner.InvokeRequired) {
     owner.Invoke(new Action<Control, string, Exception>(ShowErrorDialog), owner, message, exception);
   } else {
     using (ErrorDialog dialog = new ErrorDialog(message, exception)) {
       dialog.ShowDialog(owner);
     }
   }
 }
Example #39
0
 void resetDevice()
 {
     if (owner.InvokeRequired)
     {
         owner.Invoke(new Action(reset));
     }
     else
     {
         reset();
     }
 }
 public static void SetLabelText(System.Windows.Forms.Control Label, string Text)
 {
     if (Label.InvokeRequired == true)
     {
         Label.Invoke(new SetLabelTextInvoker(SetLabelText), Label, Text);
     }
     else
     {
         Label.Text = Text;
     }
 }
Example #41
0
 // thread safe invoker on Windows.Forms control
 internal static void ThreadSafeInvoke(this System.Windows.Forms.Control ctr, Action action)
 {
     if (ctr.InvokeRequired)
     {
         ctr.Invoke(new Action(action));
     }
     else
     {
         action();
     }
 }
Example #42
0
 public static void SafeInvoke(this System.Windows.Forms.Control control, InvokeHandler handler)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(handler);
     }
     else
     {
         handler();
     }
 }
Example #43
0
File: gui.cs Project: renyh1013/dp2
 public static string GetText(Control control)
 {
     if (control.InvokeRequired == false)
         return control.Text;
     string strText = "";
     control.Invoke((Action)(() =>
     {
         strText = control.Text;
     }));
     return strText;
 }
Example #44
0
 public static void InvokeEx(MethodInvoker invoker,Control control)
 {
     if (invoker != null && control != null && !control.IsDisposed)
     {
         while (!control.IsHandleCreated)
         {
             System.Threading.Thread.Sleep(100);
         }
         control.Invoke(invoker);
     }
 }
Example #45
0
        public override void Send(SendOrPostCallback d, object state)
        {
            Thread destinationThread = DestinationThread;

            if (destinationThread is null || !destinationThread.IsAlive)
            {
                throw new InvalidAsynchronousStateException(SR.ThreadNoLongerValid);
            }

            controlToSendTo?.Invoke(d, new object[] { state });
        }
Example #46
0
 public static void SetControlPropertyThreadSafe(System.Windows.Forms.Control control, string propertyName, object propertyValue)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
     }
     else
     {
         control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
     }
 }
Example #47
0
 internal static void SetText(Control control, string text)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(new SetTextDelegate(SetText), new object[] { control, text });
     }
     else
     {
         control.Text = text;
     }
 }
Example #48
0
 private void addControlAction(Control parent, Control child)
 {
     if (parent.InvokeRequired)
     {
         parent.Invoke(addControl, parent, child);
     }
     else
     {
         parent.Controls.Add(child);
     }
 }
Example #49
0
 /// <summary>
 /// 若有需要的話,做援引呼叫。
 /// </summary>
 /// <param name="control"></param>
 /// <param name="action"></param>
 public static void InvokeIfNecessary(this System.Windows.Forms.Control control, MethodInvoker action)
 {
     if (control.InvokeRequired)
     {
         control.Invoke(action);
     }
     else
     {
         action();
     }
 }
Example #50
0
 public static void SetButtonBackgroundColor(System.Windows.Forms.Control ButtonControl, Color bgColor)
 {
     if (ButtonControl.InvokeRequired)
     {
         SetButtonBackgroundColorCallback d = SetButtonBackgroundColor;
         ButtonControl.Invoke(d, new object[] { ButtonControl, bgColor });
     }
     else
     {
         ButtonControl.BackColor = bgColor;
     }
 }
Example #51
0
        public static bool ControlInvokeRequired(System.Windows.Forms.Control c, Action a)
        {
            if (c.InvokeRequired)
            {
                c.Invoke(new MethodInvoker(delegate { a(); }));
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #52
0
        /// <summary> Executes a delegate in the context of the main thread. </summary>
        public static object SafelyInvoke(Delegate delegateValue, object[] arguments)
        {
            WinForms.Control control = _invokeControl;                  // thread safe... int read

            if ((control != null) && control.InvokeRequired)
            {
                return(control.Invoke(delegateValue, arguments));
            }
            else
            {
                return(delegateValue.DynamicInvoke(arguments));
            }
        }
Example #53
0
 public static void SetControlToolTip(System.Windows.Forms.ToolTip toolTip, System.Windows.Forms.Control ctlSelf, string Value)
 {
     if (ctlSelf.InvokeRequired)
     {
         ctlSelf.Invoke(new MethodInvoker(delegate
         {
             toolTip.SetToolTip(ctlSelf, Value);
         }));
     }
     else
     {
         toolTip.SetToolTip(ctlSelf, Value);
     }
 }
Example #54
0
 public static void SetControlEnabled(System.Windows.Forms.Control ctlSelf, bool Value)
 {
     if (ctlSelf.InvokeRequired)
     {
         ctlSelf.Invoke(new MethodInvoker(delegate
         {
             ctlSelf.Enabled = Value;
         }));
     }
     else
     {
         ctlSelf.Enabled = Value;
     }
 }
Example #55
0
 public static void SetControlText(System.Windows.Forms.Control ctlSelf, string Value)
 {
     if (ctlSelf.InvokeRequired)
     {
         ctlSelf.Invoke(new MethodInvoker(delegate
         {
             ctlSelf.Text = Value;
         }));
     }
     else
     {
         ctlSelf.Text = Value;
     }
 }
Example #56
0
 public static void SetControlForeColor(System.Windows.Forms.Control ctlSelf, Color Value)
 {
     if (ctlSelf.InvokeRequired)
     {
         ctlSelf.Invoke(new MethodInvoker(delegate
         {
             ctlSelf.ForeColor = Value;
         }));
     }
     else
     {
         ctlSelf.ForeColor = Value;
     }
 }
Example #57
0
        public int CopyLinks(System.Windows.Forms.Control invokeHelper, params int[] ids)
        {
            var elements = GetCopyLink(
                ids.Select(id => QuickCacheLog(id))
                .OrderBy(log => log.Date)
                ).ToList();
            string res = string.Join("\n", elements);

            if (!string.IsNullOrWhiteSpace(res))
            {
                Action copy = () => System.Windows.Forms.Clipboard.SetText(res, System.Windows.Forms.TextDataFormat.Text);
                invokeHelper.Invoke(copy);
            }
            return(elements.Count());
        }
Example #58
0
 /// <summary>
 /// 刷新用户列表
 /// </summary>
 /// <param name="list">用户列表</param>
 private void DoUserChanged(UserCollection list)
 {
     if (_UserChangedHandle != null)
     {
         System.Windows.Forms.Control c = (_UserChangedHandle.Target as Control);
         if (c != null)
         {
             c.Invoke(_UserChangedHandle, list);
         }
         else
         {
             _UserChangedHandle(list);
         }
     }
 }
Example #59
0
 /// <summary>
 ///显示跟踪记录
 /// </summary>
 /// <param name="log"></param>
 private void DoWriteLog(string log)
 {
     if (_WriteLogHandle != null)
     {
         System.Windows.Forms.Control c = (_WriteLogHandle.Target as System.Windows.Forms.Control);
         if (c != null)
         {
             c.Invoke(_WriteLogHandle, log);
         }
         else
         {
             _WriteLogHandle(log);
         }
     }
 }
 public void UpdateControlCall(System.Windows.Forms.Control targetControl, string targetValue)
 {
     if (targetControl.InvokeRequired) //Invoke Method
     {
         targetControl.Invoke(updateControl, new object[] { targetControl, targetValue });
     }
     else
     {
         if (targetControl.GetType() == typeof(Label) && (targetValue == "true" || targetValue == "false"))
         {
             targetControl.Visible = Convert.ToBoolean(targetValue);
         }
         else if (targetControl.GetType() == typeof(Button) && (targetValue == "true" || targetValue == "false"))
         {
             targetControl.Visible = Convert.ToBoolean(targetValue);
         }
         else if (targetControl.GetType() == typeof(Label) && targetValue != "true" && targetValue != "false")
         {
             targetControl.Text = targetValue;
         }
         else if (targetControl.GetType() == typeof(ProgressBar) && (targetValue == "true" || targetValue == "false"))
         {
             ProgressBar tmpControl = new ProgressBar();
             tmpControl         = (ProgressBar)targetControl;
             tmpControl.Visible = Convert.ToBoolean(targetValue);
         }
         else if (targetControl.GetType() == typeof(ProgressBar) && targetValue != "true" && targetValue != "false")
         {
             ProgressBar tmpControl = new ProgressBar();
             tmpControl       = (ProgressBar)targetControl;
             tmpControl.Value = Convert.ToInt32(targetValue);
         }
         else if (targetControl.GetType() == typeof(PictureBox))
         {
             PictureBox tmpControl = new PictureBox();
             tmpControl         = (PictureBox)targetControl;
             tmpControl.Visible = Convert.ToBoolean(targetValue);
         }
         else if (targetControl.GetType() == typeof(Panel))
         {
             Panel tmpControl = new Panel();
             tmpControl         = (Panel)targetControl;
             tmpControl.Visible = Convert.ToBoolean(targetValue);
         }
     }
 }