Microsoft .NET/C#

[C#] Thread, Thread 인자 전달, BeginInvoke, Invoke 복붙용

전자기린 2021. 3. 17. 11:05

Thread

Thread th = new Thread(new ThreadStart(functionSample));
th.Start();

private void functionSample()
{
}

Thread 인자 전달

// Type - 1
Thread th = new Thread(() => functionSample("전자기린", 29));
th.Start();

private void functionSample(string name, int age)
{
}


// Type - 2
Thread th = new Thread(new ParameterizedThreadStart(functionSample));
th.Start("전자기린");

private void functionSample(object _name)
{
	string name = _name as string;
}

BeginInvoke - 비동기

Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal, 
new Action(delegate 
{

}));


//xamarin.forms
Device.BeginInvokeOnMainThread(() => {
    
});

Invoke - 동기

Application.Current.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal, 
new Action(delegate 
{

}));