C#????????????
???????????? ???????[ 2016/5/24 11:05:20 ] ????????C# .NET
????1???????????????????????????????????????????demo???£?
?????????????е??????????
namespace ThreadParameterDemo
{
public class FunctionClass
{
public static string TestFunction(string name?? int age)
{
//??????????
return name + " ?????????" + age;
}
}
}
???????????????????
namespace ThreadParameterDemo
{
///
/// ??????
///
public class TransitionalClass
{
private string name = string.Empty;
private int age;
public string acceptResults = string.Empty;
public TransitionalClass(string name?? int age)
{
this.name = name;
this.age = age;
}
public void TestFunction()
{
acceptResults = FunctionClass.TestFunction(this.name?? this.age);
}
}
}
?????????
????private void Form1_Load(object sender?? EventArgs e)
????{
????//?????ThreadWithState????????????
????TransitionalClass tc = new TransitionalClass(" Jack"?? 42);
????// ?????????????????????
????Thread t = new Thread(new ThreadStart(tc.TestFunction));
????t.Start();
????//????????????? tc.acceptResults;
????}
????С???
???????????IsBackground?????????IsBackground?false?????Windows??????????????????????????????????????????????ó???δ??????
????MSDN?????????????????????????e??????????????????У????????????Σ???Щ??ν??????????????????
????????????????????κ??????????????????????????????????????????????????????
????BackgroundWorker ??
????ThreadStart?е????????з???????????
????2?????????е??????????
??????????????????????????????????????????????ú?Thread???????????????????????????????
??????????????£?
public delegate string delegateFunction(string name??int age);//???
delegateFunction df;
private void Form1_Load(object sender?? EventArgs e)
{
//??????????????
df = new delegateFunction(FunctionClass.TestFunction);
string name = "my name";//???????
int age = 19;
IAsyncResult result = df.BeginInvoke(name??age?? null?? null);
string myResult = df.EndInvoke(result);//???????????
MessageBox.Show(myResult);
}
????????
public Func df;//???
private void Form1_Load(object sender?? EventArgs e)
{
//??????????????
df += FunctionClass.TestFunction;
string name = "my name";//???????
int age = 19;
IAsyncResult result = df.BeginInvoke(name?? age?? null?? null);
string myResult = df.EndInvoke(result);//???????????
MessageBox.Show(myResult);
}
????С???
???????????????????????????????????background??????????normal
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11