我有一些用于在后台线程中运行方法的通用函数。除了正常的线程同步问题之外,这里是否存在任何危险?
public static void ThreadRunReturn<TReturn, TArgument>(Func<TArgument, TReturn> func, TArgument arg, bool background = true)
{
Thread th = new Thread(unused => func(arg));
th.IsBackground = background;
th.Start(th);
}
public static void ThreadRunReturn<TReturn, TArgument1, TArgument2>(Func<TArgument1, TArgument2, TReturn> func, TArgument1 arg1, TArgument2 arg2, bool background = true)
{
Thread th = new Thread(unused => func(arg1, arg2));
th.IsBackground = background;
th.Start(th);
}
public static void ThreadRun<TArgument>(Action<TArgument> action, TArgument arg, bool background = true)
{
Thread th = new Thread(unused => action(arg));
th.IsBackground = background;
th.Start(th);
}
public static void ThreadRun<TArgument1, TArgument2>(Action<TArgument1, TArgument2> action, TArgument1 arg1, TArgument2 arg2, bool background = true)
{
Thread th = new Thread(unused => action(arg1, arg2));
th.IsBackground = background;
th.Start(th);
}