convert VB to C#
This commit is contained in:
78
Pilz.Threading/CrossThreadsInvokeing.cs
Normal file
78
Pilz.Threading/CrossThreadsInvokeing.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
// IDE-Voreinstellungen:
|
||||
// Option Explicit On
|
||||
// Option Strict On
|
||||
|
||||
// "My Project"-Einstellungen:
|
||||
// Imports Microsoft.VisualBasic.ControlChars
|
||||
// Imports System.Windows.Forms
|
||||
// Imports System
|
||||
|
||||
using System;
|
||||
using global::System.Windows.Forms;
|
||||
|
||||
namespace Pilz.Threading
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Stellt Methoden bereit, mit denen ein beliebiger Methoden-Aufruf mit bis zu 3 Argumenten
|
||||
/// in einen Nebenthread verlegt werden kann, bzw. aus einem Nebenthread in den Hauptthread
|
||||
/// </summary>
|
||||
public class CrossThreadsInvokeing
|
||||
{
|
||||
public static void RunAsync<T1, T2, T3>(Action<T1, T2, T3> Action, T1 Arg1, T2 Arg2, T3 Arg3)
|
||||
{
|
||||
Action.BeginInvoke(Arg1, Arg2, Arg3, Action.EndInvoke, null);
|
||||
}
|
||||
|
||||
public static void RunAsync<T1, T2>(Action<T1, T2> Action, T1 Arg1, T2 Arg2)
|
||||
{
|
||||
Action.BeginInvoke(Arg1, Arg2, Action.EndInvoke, null);
|
||||
}
|
||||
|
||||
public static void RunAsync<T1>(Action<T1> Action, T1 Arg1)
|
||||
{
|
||||
Action.BeginInvoke(Arg1, Action.EndInvoke, null);
|
||||
}
|
||||
|
||||
public static void RunAsync(Action Action)
|
||||
{
|
||||
Action.BeginInvoke(Action.EndInvoke, null);
|
||||
}
|
||||
|
||||
private static bool GuiCrossInvoke(Delegate Action, params object[] Args)
|
||||
{
|
||||
var frms = Application.OpenForms;
|
||||
if (frms.Count > 0 && frms[0].InvokeRequired)
|
||||
{
|
||||
frms[0].BeginInvoke(Action, Args);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void RunGui<T1, T2, T3>(Action<T1, T2, T3> Action, T1 Arg1, T2 Arg2, T3 Arg3)
|
||||
{
|
||||
if (!GuiCrossInvoke(Action, Arg1, Arg2, Arg3))
|
||||
Action(Arg1, Arg2, Arg3);
|
||||
}
|
||||
|
||||
public static void RunGui<T1, T2>(Action<T1, T2> Action, T1 Arg1, T2 Arg2)
|
||||
{
|
||||
if (!GuiCrossInvoke(Action, Arg1, Arg2))
|
||||
Action(Arg1, Arg2);
|
||||
}
|
||||
|
||||
public static void RunGui<T1>(Action<T1> Action, T1 Arg1)
|
||||
{
|
||||
if (!GuiCrossInvoke(Action, (object)Arg1))
|
||||
Action(Arg1);
|
||||
}
|
||||
|
||||
public static void RunGui(Action Action)
|
||||
{
|
||||
if (!GuiCrossInvoke(Action))
|
||||
Action();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user