不是web,命名空间是哪个?
using System....????????
怎么用的?
using System....????????
怎么用的?
解决方案 »
- C# 连接Access数据库,密码中有乱码,该怎么处理啊?
- 算是做好第一个程序!出乎我的意料哦!是不是我的代码的问题!
- 有个关于SQL的简单问题
- gridview中动态添加的checkbox,之后如何获取?
- WCF RESTful 权限的控制
- combobox 手动设定 选项和selectvalue
- 一个比较麻烦的需求,关于Windows Service,上传文件等,求高手指点。
- 请教大家,以下几句不太明白
- 如何用socket做一个http服务器,最好有代码,谢谢!^_^
- 请教各位仁兄,那里有C#入门的电子教程可以下载,或有什么比较好的中文网站可以上?
- 如何清除画上去的图像?
- 如何在程序中点击一个按钮,执行关闭该程序并重新启动该程序
using System.Web.Caching;
Using Cache in Your WinForms Applications
<PRE lang=cs>using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Web.Caching;
using System.Data;namespace CacheSample
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtValueToPutInCache;
private System.Windows.Forms.TextBox txtValueInCache;
private System.Windows.Forms.Button btnPutInCache;
private System.Windows.Forms.Button btnGetFromButton;
private const string CACHE_KEY = "APPCACHEKEY";
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtValueToPutInCache = new System.Windows.Forms.TextBox();
this.txtValueInCache = new System.Windows.Forms.TextBox();
this.btnPutInCache = new System.Windows.Forms.Button();
this.btnGetFromButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(113, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Value to put in cache:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(8, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(95, 16);
this.label2.TabIndex = 1;
this.label2.Text = "Value from cache:";
//
// txtValueToPutInCache
//
this.txtValueToPutInCache.Location = new System.Drawing.Point(128, 16);
this.txtValueToPutInCache.Name = "txtValueToPutInCache";
this.txtValueToPutInCache.Size = new System.Drawing.Size(200, 20);
this.txtValueToPutInCache.TabIndex = 2;
this.txtValueToPutInCache.Text = "";
//
// txtValueInCache
//
this.txtValueInCache.Location = new System.Drawing.Point(128, 40);
this.txtValueInCache.Name = "txtValueInCache";
this.txtValueInCache.ReadOnly = true;
this.txtValueInCache.Size = new System.Drawing.Size(200, 20);
this.txtValueInCache.TabIndex = 3;
this.txtValueInCache.Text = "";
//
// btnPutInCache
//
this.btnPutInCache.Location = new System.Drawing.Point(352, 16);
this.btnPutInCache.Name = "btnPutInCache";
this.btnPutInCache.Size = new System.Drawing.Size(104, 23);
this.btnPutInCache.TabIndex = 4;
this.btnPutInCache.Text = "Put in Cache";
this.btnPutInCache.Click +=
new System.EventHandler(this.btnPutInCache_Click);
//
// btnGetFromButton
//
this.btnGetFromButton.Location = new System.Drawing.Point(352, 40);
this.btnGetFromButton.Name = "btnGetFromButton";
this.btnGetFromButton.Size = new System.Drawing.Size(104, 23);
this.btnGetFromButton.TabIndex = 5;
this.btnGetFromButton.Text = "Get from Cache";
this.btnGetFromButton.Click +=
new System.EventHandler(this.btnGetFromButton_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 133);
this.Controls.Add(this.btnGetFromButton);
this.Controls.Add(this.btnPutInCache);
this.Controls.Add(this.txtValueInCache);
this.Controls.Add(this.txtValueToPutInCache);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion private void btnPutInCache_Click(object sender, System.EventArgs e)
{
AppMain.Cache.Insert(
CACHE_KEY,
txtValueToPutInCache.Text,
null,
Cache.NoAbsoluteExpiration,
TimeSpan.FromSeconds( 60 ) );
} private void btnGetFromButton_Click(object sender, System.EventArgs e)
{
string value;
value = AppMain.Cache[ CACHE_KEY ] as string;
if( null == value )
{
value = "[No value in the cache.]";
}
txtValueInCache.Text = value;
}
}
}</PRE>