rt~~
解决方案 »
- 用c# 2.0 在PDA windows mobile 6.5 环境下调用拍照程序报错,大家帮忙看下,高分相送!
- C#如何比较字符串大小???
- 一个最简的控制台程序,program类,如何实例化的呢?难道不需要实例化吗?
- Graphics.DrawLine画的操作如何刷新到PICTURE?
- 菜鸟求教不关闭子窗体的问题
- 为何我的gridview无法选取行?
- 想提取出一段文本中所有的IP地址 数字.数字.数字.数字,如何做?
- 请教 ListBox 怎么判断 里面的内容有没有被选择
- [菜鸟提问]我要编写一个信封打印系统,请高手给一些思路!!!!!
- web server?
- 2011第一帖,讨论帖------视频缩略!
- 【新手】WCF 的配置问题
using System;
using System.Threading;class Account
{
private Object thisLock = new Object();
int balance; Random r = new Random(); public Account(int initial)
{
balance = initial;
} int Withdraw(int amount)
{ // This condition will never be true unless the lock statement
// is commented out:
if (balance < 0)
{
throw new Exception("Negative Balance");
} // Comment out the next line to see the effect of leaving out
// the lock keyword:
lock(thisLock)
{
if (balance >= amount)
{
Console.WriteLine("Balance before Withdrawal : " + balance);
Console.WriteLine("Amount to Withdraw : -" + amount);
balance = balance - amount;
Console.WriteLine("Balance after Withdrawal : " + balance);
return amount;
}
else
{
return 0; // transaction rejected
}
}
} public void DoTransactions()
{
for (int i = 0; i < 100; i++)
{
Withdraw(r.Next(1, 100));
}
}
}class Test
{
static void Main()
{
Thread[] threads = new Thread[10];
Account acc = new Account(1000);
for (int i = 0; i < 10; i++)
{
Thread t = new Thread(new ThreadStart(acc.DoTransactions));
threads[i] = t;
}
for (int i = 0; i < 10; i++)
{
threads[i].Start();
}
}
}
webform中 对于缓存使用的比较多
比百度权威多了
我的是MSDN