澳门新浦京8455com在职业线程里

澳门新浦京8455com 1

澳门新浦京8455com 1

 

看了平时写的一些东西 做的一些例子 让电脑按照你的意图去显示一些东西
你会发现 “原来编程真的很有意思的”

//方法一: 
   private readonly string _NumChinese = “零壹贰叁肆伍陆柒捌玖”; 
    private readonly string _UnitChinese = “仟佰拾亿仟佰拾万仟佰拾圆角分”; 

自己写的程序,在工作线程里,因为处理的数据比较多,该工作线程执行下来要两三秒钟,太慢了;有人说用并发多线程,线程池来处理;但问题是就是不知道该怎么将这个工作线程拆分成多个子线程来有序稳定的执行,提高速度,请大佬赐教!最好能详细说下架构怎么组织以下是简化了的代码:UINTCMeasureDlg::AutoMeasureThread(LPVOIDpPAR)//工作线程{for(inti=0;i5;i++)//i为需要的数据数目;***********{switch(i){//读出第一条线的参数;case0:GetPrivateProfileString(_T(“Line1-1”),_T(“num_measures_1-1”),_T(“50”),str.GetBuffer(255),255,PathStr);m_Num_Measures_1=_ttoi(str);GetPrivateProfileString(_T(“Line1-1”),_T(“measure_length1_1-1”),_T(“30”),str.GetBuffer(255),255,PathStr);m_Measure_Length1_1=_ttoi(str);break;//读出第2条线参数;case1:GetPrivateProfileString(_T(“Line1-1”),_T(“num_measures_1-1”),_T(“50”),str.GetBuffer(255),255,PathStr);m_Num_Measures_1=_ttoi(str);GetPrivateProfileString(_T(“Line1-1”),_T(“measure_length1_1-1”),_T(“30”),str.GetBuffer(255),255,PathStr);m_Measure_Length1_1=_ttoi(str);break;//读出第3条线参数;case2:GetPrivateProfileString(_T(“Line1-1”),_T(“num_measures_1-1”),_T(“50”),str.GetBuffer(255),255,PathStr);m_Num_Measures_1=_ttoi(str);GetPrivateProfileString(_T(“Line1-1”),_T(“measure_length1_1-1”),_T(“30”),str.GetBuffer(255),255,PathStr);m_Measure_Length1_1=_ttoi(str);break;case3:break;//读出第5条线参数;case4:GetPrivateProfileString(_T(“Line1-1”),_T(“num_measures_1-1”),_T(“50”),str.GetBuffer(255),255,PathStr);m_Num_Measures_澳门新浦京8455com,1=_ttoi(str);GetPrivateProfileString(_T(“Line1-1”),_T(“measure_length1_1-1”),_T(“30”),str.GetBuffer(255),255,PathStr);m_Measure_Length1_1=_ttoi(str);break;default:break;}intdata=Function//将参数依此代入函数Data_SUM[i]=data;//将数据合并一起;}Data_SUM[i]//最后将得到的总数据输出到列表控件显示;}这是网上看到别人的做法,可以选择开多少个线程来运算,不知道是怎么个实现并发多线程的;

澳门新浦京8455com 2

 

    /// <summary> 
    /// 小写金额转化成大写金额(只支持精确到分的小写金额) 
    /// </summary> 
    /// <returns></returns> 
    public string NumCHN(double Num) 
    { 
        if (Num <= 0) return String.Empty; 

 

1 using
System;
2  using
System.Collections.Generic;
3  using
System.Linq;
4  using
System.Text;
5  using
System.Data;
6 using
System.Data.SqlClient;
7 using
System.IO;
8
9 namespace
studyDemo
10 {
11 class
Program
12 {
13 staticvoid
Main(string[] args)
14 {
15
16 //recursion(1, 0);
17 //sortDemo();
18 //commonMultiple(13, 4);
19
20 //getDir(new DirectoryInfo(@”c:”),0);
21 //numToString(757657578);
22
23 //string
str = “hello world!!”;
24 //foreach
(char c in str)
25 //
Console.WriteLine(c);
26 }
27
28 staticvoid
numToString(int num)//把整型转换成字符串
29 {
30 char[]
str = { ”,
”,
”,
”,
”,
”,
”,
”,
” };
31 int indx
=0;
32
33 while (num
>0)
34 {
35 int tmpNum
= num %10;
36 char
tmpChar;
37 switch
(tmpNum)
38 {
39 case1:
40 tmpChar =’①’;
41 break;
42 case2:
43 tmpChar =’②’;
44 break;
45 case3:
46 tmpChar =’③’;
47 break;
48 case4:
49 tmpChar =’④’;
50 break;
51 case5:
52 tmpChar =’⑤’;
53 break;
54 case6:
55 tmpChar =’⑥’;
56 break;
57 case7:
58 tmpChar =’⑦’;
59 break;
60 case8:
61 tmpChar =’⑧’;
62 break;
63 case9:
64 tmpChar =’⑨’;
65 break;
66 default:
67 tmpChar =’〇’;
68 break;
69 }
70 if (indx
< str.Length)
71 str[str.Length – indx
-1]
= tmpChar;
72 indx++;
73
74 num /=10;
75 }
76
77 Console.WriteLine(newstring(str).Trim());
78 }
79
80 staticvoid
commonMultiple(int num1, int
num2)//求最小公倍数 的算法
81 {
82 int comNum
=0;
83 int tmp
=-1;
84 if (num1
> num2)
85 {
86 tmp = num1;
87 num1 = num2;
88 num2 = tmp;
89 }
90
91 for
(int i = num2; i
<= num1 * num2;
i++)
92 {
93 if (i
% num1 ==0&& i
% num2 ==0)
94 {
95 comNum = i;
96 break;
97 }
98 }
99 if (tmp
==-1)
100 Console.WriteLine(“{0}跟{1}的最小公倍数是:{2}”, num1,
num2, comNum);
101 else
102 Console.WriteLine(“{0}跟{1}的最小公倍数是:{2}”,num2
,num1 , comNum);
103 }
104
105 staticvoid
sortDemo()//排序算法
106 {
107 int[] arr
= { 4,
5, 3,
678, 12,
78, 90,
1 };
108
109 for
(int i =0; i
< arr.Length; i++)
110 {
111 for
(int j =0; j
< arr.Length -1;
j++)
112 {
113 if (arr[j
+1]
> arr[j])
114 {
115 int tmp;
116 tmp =
arr[j];
117 arr[j] = arr[j
+1];
118 arr[j +1]
= tmp;
119 }
120 }
121 }
122
123 foreach
(int n in arr)
124 {
125 Console.WriteLine(n);
126 }
127 }
128
129 staticvoid
getDir(DirectoryInfo dir, int
level)//递归算法 遍历目录
130 {
131 foreach
(DirectoryInfo d in dir.GetDirectories())
132 {
133 for
(int i =0; i
< level; i++)
134 Console.Write(“”);
135 Console.WriteLine(d.Name);
136 getDir(d, level +1);
137 }
138 }
139
140 staticvoid
recursion(int node, int
level)//递归算法 树状图
141 {
142 //数据库里表的结构:
143 /*
144 * create table tree
145 * (
146 * id int primary key identity (1,1) ,
147 * nm varchar(20),
148 * pId int
149 * )
150 * id主键自增列 nm名称 pId父ID(从属于)
151 */
152 string sql
=”select *
from tree where pid=@1″;
153 SqlConnection conn =new
SqlConnection(@”server=.sqlexpress;database=tempdb;Integrated
Security=true”);
154 conn.Open();
155
156 SqlCommand cmd =new
SqlCommand(sql, conn);
157 cmd.Parameters.Add(new
SqlParameter(“@1”,
node));
158
159 SqlDataReader dr =
cmd.ExecuteReader();
160
161 while
(dr.Read())
162 {
163 for
(int i =0; i
<= level; i++)
164 Console.Write(“—“);
165 Console.WriteLine(dr[“nm”]);
166 int id
= dr.GetInt32(0);
167
168 SqlConnection conn2 =new
SqlConnection(@”server=.sqlexpress;database=tempdb;Integrated
Security=true”);
169 conn2.Open();
170 SqlCommand cmd2 =new
SqlCommand(“select count(*) from tree where
pid=@1”, conn2);
171 cmd2.Parameters.Add(new
SqlParameter(“@1”, id));
172 object
hasChild = cmd2.ExecuteScalar();
173 if
(Convert.ToInt32(hasChild) !=0)
174 recursion(id, level +1);
175
176 conn2.Close();
177 }
178
179 dr.Close();
180 conn.Close();
181 }
182 }
183 }
184

        string sNum = Num.ToString(“F”); 

private void button1_Click(object sender, EventArgs e)

 

        if (sNum.IndexOf(“.”) < 0)//对小数位的处理 
            sNum += “00”; 
        else 
            sNum = sNum.Replace(“.”, String.Empty); 

{

 

        string sNumCHN = String.Empty; 

  textBox2.Text =
ConvertNumberToChinese(Convert.ToDouble(textBox1.Text));

        if (sNum.Length > _UnitChinese.Length) 
            throw new Exception(“数值太大,无法转化!”); 

}

        int nPosition = _UnitChinese.Length – sNum.Length; 

 

        for (int i = 0; i < sNum.Length; i++) 
        { 
            string cNum = sNum.Substring(i, 1); 

相关文章

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图