趣味小问题,感兴趣的进 N(假如10)个职员在屋里,每个人每分钟都要向领导交1块钱,最长时间M(假如20)分钟也要交的,如果过了10分钟了,有人还没交,领导就要催促那些没交的人,让他们交钱.程序模拟实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先说出你自己的suggestion 嘛 原来是 wow里面大boss的仇恨列表每个人一个sessioid,同时一个hashtable里面存如sessioid和仇恨值。如果有人有拉仇恨的动作,就根据sessionid找到他的仇恨值,增加仇恨值而大boss呢,定时减少所有session的仇恨值也就是如果没人有动作所有人的仇恨值都减少相同量,如果有人做出增加仇恨的动作,则此人仇恨增加 你得给出你的现有设计的细节,什么业务逻辑,你的监控放在内存还是数据库,上下文是什么,等等。你可以简化你的模型,那样也好给你个demo。 员工应缴钱=?员工实缴钱=?for {员工应交钱- 员工实际交钱>=10发通知交钱}完美解决鼓掌~ 员工应缴钱=当前时间计算获得员工实缴钱=员工缴钱列表for {员工应交钱- 员工实际交钱>=10发通知交钱} using System;using System.Collections.Generic;using System.Threading;namespace WindowsFormsApplication4{ /// <summary> /// 领导 /// </summary> public class Leader : IDisposable { #region 成员变量 /// <summary> /// 员工列表 /// </summary> private IDictionary<String, Employee> _EmployeeList; /// <summary> /// 服务状态 /// </summary> private Boolean _Active; /// <summary> /// 超时时间 /// </summary> private readonly Int64 _TimeOutTick; #endregion #region 私有方法 /// <summary> /// 1秒轮询一次,找出没交保护费的员工 /// </summary> /// <param name="obj"></param> private void Polling(Object obj) { while (_Active) { try { foreach (String key in _EmployeeList.Keys) { Employee item = _EmployeeList[key]; if ((DateTime.Now.Ticks - item.LastActiveTime) > _TimeOutTick) { item.Urged(); } } } finally { Thread.Sleep(1000); } } } #endregion #region 公有方法 /// <summary> /// 构造函数 /// </summary> public Leader() { // 10秒断线 _TimeOutTick = 10 * 10000000; _Active = false; } /// <summary> /// 设置员工列表 /// </summary> /// <param name="employeeList"></param> public void SetEmployeeList(Dictionary<String, Employee> employeeList) { _EmployeeList = employeeList; } /// <summary> /// 启动 /// </summary> public void Start() { _Active = true; ThreadPool.QueueUserWorkItem(new WaitCallback(Polling), null); } /// <summary> /// 收费 /// </summary> /// <param name="Name"></param> public void Charge(String Name) { try { Employee employee; if (_EmployeeList.TryGetValue(Name, out employee)) { employee.LastActiveTime = System.DateTime.Now.Ticks; } } finally { } } /// <summary> /// 释放资源 /// </summary> public void Dispose() { if (_Active) { _Active = false; _EmployeeList.Clear(); _EmployeeList = null; } } #endregion }}using System;using System.Windows.Forms;namespace WindowsFormsApplication4{ /// <summary> /// 用户信息 /// </summary> public class Employee { /// <summary> /// 姓名 /// </summary> public String Name { get; set; } /// <summary> /// 最后活跃时间 /// </summary> public Int64 LastActiveTime { get; set; } /// <summary> /// 领导 /// </summary> private Leader _Leader; /// <summary> /// 构造函数 /// </summary> /// <param name="name"></param> /// <param name="leader"></param> public Employee(String name, Leader leader) { Name = name; LastActiveTime = DateTime.Now.Ticks; _Leader = leader; } /// <summary> /// 交保护费 /// </summary> public void PayProtectionMoney() { _Leader.Charge(Name); } /// <summary> /// 催交 /// </summary> public void Urged() { MessageBox.Show(String.Format("{0} 该交保护费了,不然~~~~", Name)); } }}using System;using System.Collections.Generic;using System.Windows.Forms;namespace WindowsFormsApplication4{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } Dictionary<String, Employee> _EmployeeList = new Dictionary<String, Employee>(); private void button1_Click(object sender, EventArgs e) { Leader leader= new Leader(); String name = String.Empty; for (Int32 i = 0; i < 100;i++) { name = String.Format("employee" + i); Employee employee = new Employee(name, leader); _EmployeeList.Add(name, employee); } leader.SetEmployeeList(_EmployeeList); leader.Start(); } private void button2_Click(object sender, EventArgs e) { _EmployeeList["employee1"].PayProtectionMoney(); } }}简单问题复杂化 急,急,急,一个批处理文件中怎么执行多个exe程序??? 精度问题 关于安装文件的快捷方式的问题 c#net2005打包 如何把应用程序程序和ORACLE客户端一起打包 测试winform的C/S结构的工具有哪些? 如何通过点击WinForm下一弹出窗口中的链接,直接跳转到指定的网页? C# array问题 求文中提到的方法代码 CMS源码下载 紧急求助!!如何用c#获取当前虚拟目录所在的物理路径 如何实现跨域登陆 数据库插入图片代码为什么出错???
如果有人有拉仇恨的动作,就根据sessionid找到他的仇恨值,增加仇恨值
而大boss呢,定时减少所有session的仇恨值也就是如果没人有动作所有人的仇恨值都减少相同量,如果有人做出增加仇恨的动作,则此人仇恨增加
员工实缴钱=?
for
{
员工应交钱- 员工实际交钱>=10
发通知交钱
}
完美解决鼓掌~
员工实缴钱=员工缴钱列表
for
{
员工应交钱- 员工实际交钱>=10
发通知交钱
}
using System.Collections.Generic;
using System.Threading;namespace WindowsFormsApplication4
{
/// <summary>
/// 领导
/// </summary>
public class Leader : IDisposable
{
#region 成员变量 /// <summary>
/// 员工列表
/// </summary>
private IDictionary<String, Employee> _EmployeeList; /// <summary>
/// 服务状态
/// </summary>
private Boolean _Active; /// <summary>
/// 超时时间
/// </summary>
private readonly Int64 _TimeOutTick; #endregion #region 私有方法 /// <summary>
/// 1秒轮询一次,找出没交保护费的员工
/// </summary>
/// <param name="obj"></param>
private void Polling(Object obj)
{
while (_Active)
{
try
{
foreach (String key in _EmployeeList.Keys)
{
Employee item = _EmployeeList[key];
if ((DateTime.Now.Ticks - item.LastActiveTime) > _TimeOutTick)
{
item.Urged();
}
}
}
finally
{
Thread.Sleep(1000);
}
}
} #endregion #region 公有方法 /// <summary>
/// 构造函数
/// </summary>
public Leader()
{
// 10秒断线
_TimeOutTick = 10 * 10000000; _Active = false;
} /// <summary>
/// 设置员工列表
/// </summary>
/// <param name="employeeList"></param>
public void SetEmployeeList(Dictionary<String, Employee> employeeList)
{
_EmployeeList = employeeList;
} /// <summary>
/// 启动
/// </summary>
public void Start()
{
_Active = true; ThreadPool.QueueUserWorkItem(new WaitCallback(Polling), null);
} /// <summary>
/// 收费
/// </summary>
/// <param name="Name"></param>
public void Charge(String Name)
{
try
{
Employee employee;
if (_EmployeeList.TryGetValue(Name, out employee))
{
employee.LastActiveTime = System.DateTime.Now.Ticks;
}
}
finally
{
}
} /// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
if (_Active)
{
_Active = false; _EmployeeList.Clear();
_EmployeeList = null;
}
} #endregion
}
}using System;
using System.Windows.Forms;namespace WindowsFormsApplication4
{
/// <summary>
/// 用户信息
/// </summary>
public class Employee
{
/// <summary>
/// 姓名
/// </summary>
public String Name
{
get;
set;
} /// <summary>
/// 最后活跃时间
/// </summary>
public Int64 LastActiveTime
{
get;
set;
} /// <summary>
/// 领导
/// </summary>
private Leader _Leader; /// <summary>
/// 构造函数
/// </summary>
/// <param name="name"></param>
/// <param name="leader"></param>
public Employee(String name, Leader leader)
{
Name = name;
LastActiveTime = DateTime.Now.Ticks;
_Leader = leader;
} /// <summary>
/// 交保护费
/// </summary>
public void PayProtectionMoney()
{
_Leader.Charge(Name);
} /// <summary>
/// 催交
/// </summary>
public void Urged()
{
MessageBox.Show(String.Format("{0} 该交保护费了,不然~~~~", Name));
}
}
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} Dictionary<String, Employee> _EmployeeList = new Dictionary<String, Employee>();
private void button1_Click(object sender, EventArgs e)
{
Leader leader= new Leader(); String name = String.Empty; for (Int32 i = 0; i < 100;i++)
{
name = String.Format("employee" + i); Employee employee = new Employee(name, leader);
_EmployeeList.Add(name, employee);
} leader.SetEmployeeList(_EmployeeList);
leader.Start();
} private void button2_Click(object sender, EventArgs e)
{
_EmployeeList["employee1"].PayProtectionMoney();
}
}
}简单问题复杂化