请问各位高手如何对静态变量做同步操作锁? 看看行不行。http://samples.gotdotnet.com/quickstart/aspplus/doc/applications.aspx 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class NSQS : WebService { Hashtable stockItems; Hashtable logins; public NSQS() { string stockData = null; // populate stock items this.stockItems = new Hashtable(); for(int i = 0; i < 50; i++) { stockData = "" + i; this.stockItems.Add(stockData , new StockItem(stockData, stockData, stockData, stockData, stockData, stockData)); } this.logins = new Hashtable(); logins.Add("admin", "admin"); logins.Add("testuser", "testuser"); logins.Add("test", "test"); if(Application["stockItems"] == null) { Application.Lock(); Application["stockItems"] = this.stockItems; Application.UnLock(); } if(Application["logins"] == null) { Application.Lock(); Application["logins"] = this.logins; Application.UnLock(); } } [WebMethod] public bool validateLogin(string login, string passwd) { bool res = false; string loginPasswd = (string) logins[login]; if ((loginPasswd != null) || (passwd != null)) // || (!loginPasswd.Equal(passwd))) { res = loginPasswd.Equals(passwd); return res; } [WebMethod] public void addStockItem(string code, string name, string desc, string highVal, string lowVal, string currentPrice) { StockItem stockItem = new StockItem(code, name, desc, highVal, lowVal, currentPrice); this.stockItems = (Hashtable) Application["stockItems"]; stockItems.Add(code, stockItem); Application.Lock(); //Application.Add("stockItems", this.stockItems); Application["stockItems"] = this.stockItems; Application.UnLock(); //stockItems.Add("1000", stockItem); //return queryStockItemByCode(code); } } 用application.lock 试试 我要的不是application对象的啊,朋友们 public a as filestream=new filestream(.....) 'Lock Monitor.Enter(a) 'write a....... 'Unlock the queue. Monitor.Exit(a) FormsAuthenticationTicket 类isPersistent属性 做这样一个网站 如何将DataTable类型转换成ArrayList类型 怎样获知用户是从哪个网页地址转入到我的网页地址的?(很想知道,很想) 十万火急!!! 在发一贴 .net如何绘制立体图,并在其内再添加立体图... asp.net masterpage 程序动态生成linkbutton后的点击问题 请问链接打开的窗体如何实现父窗体的关闭也关闭子窗体? web.config 无法识别的配置节 profile ASP.NET到底算是一种语言还是什么?? ASP.NET怎样学呀????????? 编写用户控件
{ Hashtable stockItems;
Hashtable logins; public NSQS() { string stockData = null; // populate stock items
this.stockItems = new Hashtable(); for(int i = 0; i < 50; i++) {
stockData = "" + i;
this.stockItems.Add(stockData , new StockItem(stockData, stockData, stockData, stockData, stockData, stockData));
} this.logins = new Hashtable(); logins.Add("admin", "admin");
logins.Add("testuser", "testuser");
logins.Add("test", "test"); if(Application["stockItems"] == null)
{
Application.Lock();
Application["stockItems"] = this.stockItems;
Application.UnLock();
} if(Application["logins"] == null)
{
Application.Lock();
Application["logins"] = this.logins;
Application.UnLock();
}
} [WebMethod]
public bool validateLogin(string login, string passwd) {
bool res = false;
string loginPasswd = (string) logins[login]; if ((loginPasswd != null) || (passwd != null)) // || (!loginPasswd.Equal(passwd))) {
res = loginPasswd.Equals(passwd); return res;
} [WebMethod]
public void addStockItem(string code, string name, string desc, string highVal, string lowVal, string currentPrice) { StockItem stockItem = new StockItem(code, name, desc, highVal, lowVal, currentPrice); this.stockItems = (Hashtable) Application["stockItems"];
stockItems.Add(code, stockItem); Application.Lock();
//Application.Add("stockItems", this.stockItems);
Application["stockItems"] = this.stockItems;
Application.UnLock(); //stockItems.Add("1000", stockItem); //return queryStockItemByCode(code);
} }
用application.lock 试试
'Lock
Monitor.Enter(a)
'write
a.......
'Unlock the queue.
Monitor.Exit(a)