Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Invoke(Control ctrl, Action action)
- {
- if (ctrl == null)
- throw new ArgumentNullException("ctrl");
- if (action == null)
- return;
- var invokeRequired = ctrl.InvokeRequired;
- try
- {
- if (ctrl.InvokeRequired)
- ctrl.Invoke(action);
- else
- action();
- }
- catch (Exception ex)
- {
- throw new Exception(String.Format("Invoke error, ctrl={0}, action Target={1}", ctrl.Name, action.Target), ex);
- }
- }
- public static void Invoke(Control ctrl, Action action, string context)
- {
- if (ctrl == null)
- throw new ArgumentNullException("ctrl");
- if (action == null)
- return; //not sure it's worththrowing an exception here...
- var invokeRequired = ctrl.InvokeRequired;
- try
- {
- if (invokeRequired)
- ctrl.Invoke(action);
- else
- action();
- }
- catch (Exception ex)
- {
- var ps = invokeRequired ? "" : " - has the target control been initialised?";
- var errmsg = String.Format("Invoke error, ctrl={0}, action Target={1}, context={2}{3}", ctrl.Name, action.Target, context, ps);
- throw new Exception(errmsg, ex);
- }
- }
Add Comment
Please, Sign In to add comment