Guest User

Untitled

a guest
Jun 23rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. if (this.InvokeRequired)
  2. {
  3. BeginInvoke(new MyDelegate(delegate()
  4. {
  5. timer.Enabled = true;
  6. }));
  7. }
  8.  
  9. public bool TimerEnable
  10. {
  11. set
  12. {
  13. this.Invoke((MethodInvoker)delegate
  14. {
  15. this.timer.Enabled = value;
  16. });
  17. }
  18. }
  19.  
  20.  
  21. public static void timerEnable()
  22. {
  23. var form = Form.ActiveForm as Form1;
  24. if (form != null)
  25. form.TimerEnable = true;
  26. }
  27.  
  28. public static class ControlExtensions
  29. {
  30. public static TResult InvokeEx<TControl, TResult>(this TControl control,
  31. Func<TControl, TResult> func)
  32. where TControl : Control
  33. {
  34. if (control.InvokeRequired)
  35. {
  36. return (TResult)control.Invoke(func, control);
  37. }
  38. else
  39. {
  40. return func(control);
  41. }
  42. }
  43. }
  44.  
  45. new Thread(() =>
  46. {
  47. Thread.Sleep(1000);
  48. this.InvokeEx(f => f.timer1.Enabled = true);
  49. }).Start();
Add Comment
Please, Sign In to add comment