0
백그라운드 스레드에서 메서드를 실행하기위한 몇 가지 일반적인 함수가 있습니다. 정상적인 스레드 동기화 문제 외에 여기에 위험이 있습니까?다른 스레드에서 함수를 실행하기위한 C# generic
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);
}
모든 것이 공개되어야합니까? – KingCronus
TPL을 더 쉽게 사용하지 않습니까? 'Task.Factory.StartNew' –
@ L.B Task를 살펴 보겠습니다 .Factory.StartNew,하지만 빠른 눈으로는 간단하지가 않습니다. 나는 다음을 할 수 있기를 원한다. MyClass.ThreadRunReturn (RunSShCommand, "reboot"); – Marinara54uc3