20150907
2015-09-07 15:17
274 查看
利用DataRow,Select DataSet中的数据
DataTable dt = GetDateSet("select * from QSDB_IMPORT_JOB").Tables[0];
DataRow[] rows = dt.Select("underlying='0017.HK'");
foreach (DataRow row in rows)
{
Console.WriteLine(row["REGION"].ToString());
}
线程池
public class TaskInfo
{
public string Boilerplate;
public int Value;
// the information needed for the task.
public TaskInfo(string text, int number)
{
Boilerplate = text;
Value = number;
}
}
static void Main(string[] args)
{
TaskInfo ti = new TaskInfo("This report displays the number {0}.", 42);
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), ti); //Params: functions and parameters the function need to use
Thread.Sleep(1000);
Console.ReadKey();
}
static void ThreadProc(Object stateInfo)
{
TaskInfo ti = (TaskInfo)stateInfo;
Console.WriteLine(ti.Boilerplate, ti.Value);
}
/*
类似互斥锁,但它可以允许多个线程同时访问一个共享资源
通过使用一个计数器来控制对共享资源的访问,如果计数器大于0,就允许访问,如果等于0,就拒绝访问。计数器累计的是“许可证”的数目,为了访问某个资源。线程必须从信号量获取一个许可证。
通常在使用信号量时,希望访问共享资源的线程将尝试获取一个许可证,如果信号量的计数器大于0,线程将获取一个许可证并将信号量的计数器减1,否则先线程将阻塞,直到获取一个许可证;当线程不再需要共享资源时,将释放锁拥有的许可证,并将许可证的数量加1,如果有其他的线程正在等待许可证,那么该线程将立刻获取许可证。*/
class mythread
{
public Thread thrd;
//创建一个可授权2个许可证的信号量,且初始值为2
static Semaphore sem = new Semaphore(2, 2);
public mythread(string name)
{
thrd = new Thread(this.run);
thrd.Name = name;
thrd.Start();
}
void run()
{
Console.WriteLine(thrd.Name + "wait for premission");
//申请一个许可证
sem.WaitOne();
Console.WriteLine(thrd.Name + "premitted……");
for (int i = 0; i < 4; i++)
{
Console.WriteLine(thrd.Name + ": " + i);
Thread.Sleep(1000);
}
Console.WriteLine(thrd.Name + " release……");
//释放
sem.Release();
}
}
class mysemaphore
{
public static void Main()
{
mythread mythrd1 = new mythread("Thrd #1");
mythread mythrd2 = new mythread("Thrd #2");
mythread mythrd3 = new mythread("Thrd #3");
mythread mythrd4 = new mythread("Thrd #4");
mythrd1.thrd.Join();
mythrd2.thrd.Join();
mythrd3.thrd.Join();
mythrd4.thrd.Join();
}
}
DataTable dt = GetDateSet("select * from QSDB_IMPORT_JOB").Tables[0];
DataRow[] rows = dt.Select("underlying='0017.HK'");
foreach (DataRow row in rows)
{
Console.WriteLine(row["REGION"].ToString());
}
线程池
public class TaskInfo
{
public string Boilerplate;
public int Value;
// the information needed for the task.
public TaskInfo(string text, int number)
{
Boilerplate = text;
Value = number;
}
}
static void Main(string[] args)
{
TaskInfo ti = new TaskInfo("This report displays the number {0}.", 42);
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), ti); //Params: functions and parameters the function need to use
Thread.Sleep(1000);
Console.ReadKey();
}
static void ThreadProc(Object stateInfo)
{
TaskInfo ti = (TaskInfo)stateInfo;
Console.WriteLine(ti.Boilerplate, ti.Value);
}
/*
类似互斥锁,但它可以允许多个线程同时访问一个共享资源
通过使用一个计数器来控制对共享资源的访问,如果计数器大于0,就允许访问,如果等于0,就拒绝访问。计数器累计的是“许可证”的数目,为了访问某个资源。线程必须从信号量获取一个许可证。
通常在使用信号量时,希望访问共享资源的线程将尝试获取一个许可证,如果信号量的计数器大于0,线程将获取一个许可证并将信号量的计数器减1,否则先线程将阻塞,直到获取一个许可证;当线程不再需要共享资源时,将释放锁拥有的许可证,并将许可证的数量加1,如果有其他的线程正在等待许可证,那么该线程将立刻获取许可证。*/
class mythread
{
public Thread thrd;
//创建一个可授权2个许可证的信号量,且初始值为2
static Semaphore sem = new Semaphore(2, 2);
public mythread(string name)
{
thrd = new Thread(this.run);
thrd.Name = name;
thrd.Start();
}
void run()
{
Console.WriteLine(thrd.Name + "wait for premission");
//申请一个许可证
sem.WaitOne();
Console.WriteLine(thrd.Name + "premitted……");
for (int i = 0; i < 4; i++)
{
Console.WriteLine(thrd.Name + ": " + i);
Thread.Sleep(1000);
}
Console.WriteLine(thrd.Name + " release……");
//释放
sem.Release();
}
}
class mysemaphore
{
public static void Main()
{
mythread mythrd1 = new mythread("Thrd #1");
mythread mythrd2 = new mythread("Thrd #2");
mythread mythrd3 = new mythread("Thrd #3");
mythread mythrd4 = new mythread("Thrd #4");
mythrd1.thrd.Join();
mythrd2.thrd.Join();
mythrd3.thrd.Join();
mythrd4.thrd.Join();
}
}
相关文章推荐
- 双击更新所有已安装的python模块
- android自动化工具之--Monkey log分析说明
- ios时间处理
- Tomcat实现多域名之间session共享
- Swift-边读边记-[1]
- 阅读《Android 从入门到精通》(2)——熟悉开发环境
- 1-4 Zabbix 用户管理
- linux(centos)下SVN服务器如何搭建
- python查询mysql,返回json
- 多线程之取钱
- Mac OS X 下安装 Ant
- 7、java5线程池之单一线程池newSingleThreadExecutor
- List 与 table 分组(group by )
- hadoop配置问题--jps线程不全
- 支付宝支付与微信支付服务端回调notify_url数据的区别
- 视频播放flvplayer插件的使用demo
- signal(SIGPIPE, SIG_IGN)作用
- HDU 2289 Cup
- 隐藏字符串的个别字段
- 实现两个不同高度的UILabel的文字底部相对于下划线对齐。不是很简单吗? 是吗?你敢按你常规方法试试让你那火眼金睛的设计、美工去瞧瞧???