C#怎么建立多线程类
答案:1 悬赏:30 手机版
解决时间 2021-03-22 19:08
- 提问者网友:謫仙
- 2021-03-22 07:53
C#怎么建立多线程类
最佳答案
- 五星知识达人网友:第四晚心情
- 2021-03-22 08:21
public class MyClass{
public MyClass(){
a = 0;
c = false;
(__privateThread = new System.Threading.Thread(new System.Threading.ThreadStart(__privateThreadMethod)) { IsBackground = true }).Start();
}
private System.Threading.Thread __privateThread;
private void __privateThreadMethod(){
//do anything u want here
//example follow:
int d = 0;
while(true){
//public method C set the switch value to all process,if set True,the do the thread works,set False and it will do nothing
if(c){
//public method A let the private variable 'a' add 1 once,and here the private thread method limit variable 'a' less than 10
if(a >= 0) a = 0;
//public method B return the System.String with total sum of variable 'a''s value changed every time
if(!d.Equals(a))d = (b += a);
}
System.Threading.Thread.Sleep(100);
}
}
private int a;
private bool c;
public void A(){
a++;
//debug code
Console.Write(a.ToString());
}
public string B(){
return this.b.ToString();
}
public void C(bool c){
this.c = c;
}
}
a simple example for u,no thanks;)
public MyClass(){
a = 0;
c = false;
(__privateThread = new System.Threading.Thread(new System.Threading.ThreadStart(__privateThreadMethod)) { IsBackground = true }).Start();
}
private System.Threading.Thread __privateThread;
private void __privateThreadMethod(){
//do anything u want here
//example follow:
int d = 0;
while(true){
//public method C set the switch value to all process,if set True,the do the thread works,set False and it will do nothing
if(c){
//public method A let the private variable 'a' add 1 once,and here the private thread method limit variable 'a' less than 10
if(a >= 0) a = 0;
//public method B return the System.String with total sum of variable 'a''s value changed every time
if(!d.Equals(a))d = (b += a);
}
System.Threading.Thread.Sleep(100);
}
}
private int a;
private bool c;
public void A(){
a++;
//debug code
Console.Write(a.ToString());
}
public string B(){
return this.b.ToString();
}
public void C(bool c){
this.c = c;
}
}
a simple example for u,no thanks;)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯