Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. new Thread(() => GetMessage(userId, false)).Start();
  2.  
  3. using System;
  4. using System.Windows.Forms;
  5.  
  6. namespace Tools
  7. {
  8. public static class InvokeHelper
  9. {
  10. public static void SafeInvoke(this Control control, Action action)
  11. {
  12. if(control.InvokeRequired) {
  13. control.Invoke(action);
  14. return;
  15. }
  16. action();
  17. }
  18.  
  19. public static void SafeInvoke(this Control control, Action action, T obj)
  20. {
  21. if(control.InvokeRequired) {
  22. control.Invoke(action, obj);
  23. return;
  24. }
  25. action(obj);
  26. }
  27.  
  28. public static void SafeInvoke(this Control control, Action action, T1 obj1, T2 obj2, T3 obj3)
  29. {
  30. if(control.InvokeRequired) {
  31. control.Invoke(action, obj1, obj2, obj3);
  32. return;
  33. }
  34. action(obj1, obj2, obj3);
  35. }
  36.  
  37. public static void SafeAsyncInvoke(this Control control, Action action)
  38. {
  39. if(control.InvokeRequired) {
  40. control.BeginInvoke(action);
  41. return;
  42. }
  43. action();
  44. }
  45.  
  46. public static void SafeAsyncInvoke(this Control control, Action action, T obj)
  47. {
  48. if(control.InvokeRequired) {
  49. control.BeginInvoke(action, obj);
  50. return;
  51. }
  52. action(obj);
  53. }
  54.  
  55. public static void SafeAsyncInvoke(this Control control, Action action, T1 obj1, T2 obj2)
  56. {
  57. if(control.InvokeRequired) {
  58. control.BeginInvoke(action, obj1, obj2);
  59. return;
  60. }
  61. action(obj1, obj2);
  62. }
  63.  
  64. public static void SafeAsyncInvoke(this Control control, Action action, T1 obj1, T2 obj2, T3 obj3)
  65. {
  66. if(control.InvokeRequired) {
  67. control.BeginInvoke(action, obj1, obj2, obj3);
  68. return;
  69. }
  70. action(obj1, obj2, obj3);
  71. }
  72. }
  73. }
  74.  
  75. private string GetMessage(int userId, bool expression)
  76. {
  77. if(this.InvokeRequired) {
  78. this.SafeInvoke(SetText, userId, expression);
  79. return;
  80. }
  81. // . . .
  82. return _richtextbox.Text;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement