using System.Threading.Tasks;
public static void Main()
ICSBankService service = new ICSBankService();
var tasks = new Task[10];
for (int i = 0; i < tasks.Length; i++)
tasks[i] = Task.Run(() => RandomlyWithdrawalAmount(service));
static void RandomlyWithdrawalAmount(ICSBankService account)
int rnd_Amount = GenerateRandomAmount();
account.WithdrawalMyMoney(rnd_Amount);
private static int GenerateRandomAmount()
var rnd = new Random(Guid.NewGuid().GetHashCode());
var amount = rnd.Next(25, 100);
public class ICSBankService
public void WithdrawalMyMoney(int amount)
bool isMoneyEnough = _totalMoney > 0 && (_totalMoney - amount) > 0;
Console.WriteLine(string.Format("本次提款:{0},餘額不足僅剩:{1}" , amount, _totalMoney));
if(!ReduceMyMoney(amount)){
Console.WriteLine(string.Format("本次提款:{0},餘額不足僅剩:{1}" , amount, _totalMoney));
Console.WriteLine(string.Format("本次提款:{0},餘額剩下:{1}" , amount, _totalMoney));
public bool ReduceMyMoney(int withdrawalAmount)
int amount = _totalMoney - withdrawalAmount;