Click here to Skip to main content
15,891,529 members
Home / Discussions / C#
   

C#

 
GeneralRe: SetWindowsHookEx fails on VS Express and work on VS2003 Pin
ranzask24-Jan-06 14:52
ranzask24-Jan-06 14:52 
GeneralRe: SetWindowsHookEx fails on VS Express and work on VS2003 Pin
Heath Stewart24-Jan-06 15:45
protectorHeath Stewart24-Jan-06 15:45 
QuestionDefaultValueAttribute Pin
tylerl24-Jan-06 10:07
tylerl24-Jan-06 10:07 
AnswerRe: DefaultValueAttribute Pin
Heath Stewart24-Jan-06 11:30
protectorHeath Stewart24-Jan-06 11:30 
QuestionSelf-deleting hashtable entries Pin
User 665824-Jan-06 10:02
User 665824-Jan-06 10:02 
AnswerRe: Self-deleting hashtable entries Pin
tylerl24-Jan-06 10:11
tylerl24-Jan-06 10:11 
GeneralRe: Self-deleting hashtable entries Pin
User 665824-Jan-06 12:58
User 665824-Jan-06 12:58 
AnswerRe: Self-deleting hashtable entries Pin
tarasn24-Jan-06 10:14
tarasn24-Jan-06 10:14 
I think the System.Web.Caching.Cache class is what are you looking for ... Wink | ;-)
You can use it in WinForms application as shown below:
<br />
using System.Threading;<br />
using System.Web;<br />
using System.Web.Caching;<br />
<br />
namespace WindowsApplication8<br />
{<br />
	/// <summary><br />
	/// Cache for Windows Forms<br />
	/// </summary><br />
	public sealed class WinCache<br />
	{<br />
		private static HttpRuntime _httpRuntime;<br />
<br />
		public static Cache Cache<br />
		{<br />
			get<br />
			{<br />
				EnsureHttpRuntime();<br />
				return HttpRuntime.Cache;<br />
			}<br />
		}<br />
<br />
		private static void EnsureHttpRuntime()<br />
		{<br />
			if( null == _httpRuntime )<br />
			{<br />
			 try<br />
			 {<br />
				Monitor.Enter( typeof( WinCache ) );<br />
				if( null == _httpRuntime )<br />
			        {<br />
			// Create an Http context to give us access to the cache.<br />
			         _httpRuntime = new HttpRuntime();<br />
			        }<br />
			}<br />
			finally<br />
			{<br />
			 Monitor.Exit( typeof( WinCache ) );<br />
			}<br />
		}<br />
	}<br />
 }<br />
}<br />
<br />


Then you can easily insert the values into WinCache in following way:
<br />
WinCache.Cache.Insert("Bob", 4, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);<br />
WinCache.Cache.Insert("John", 10, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);<br />








DevIntelligence.com - My blog for .Net Developers

-- modified at 17:31 Tuesday 24th January, 2006
GeneralRe: Self-deleting hashtable entries Pin
Dan Neely24-Jan-06 10:43
Dan Neely24-Jan-06 10:43 
GeneralRe: Self-deleting hashtable entries Pin
tarasn24-Jan-06 11:24
tarasn24-Jan-06 11:24 
GeneralRe: Self-deleting hashtable entries Pin
User 665824-Jan-06 12:56
User 665824-Jan-06 12:56 
GeneralRe: Self-deleting hashtable entries Pin
tarasn24-Jan-06 20:41
tarasn24-Jan-06 20:41 
QuestionManaged DirectX Question. Pin
cvetant24-Jan-06 9:03
cvetant24-Jan-06 9:03 
AnswerRe: Managed DirectX Question. Pin
James Gupta24-Jan-06 9:36
professionalJames Gupta24-Jan-06 9:36 
GeneralRe: Managed DirectX Question. Pin
cvetant24-Jan-06 9:45
cvetant24-Jan-06 9:45 
GeneralRe: Managed DirectX Question. Pin
James Gupta24-Jan-06 11:36
professionalJames Gupta24-Jan-06 11:36 
GeneralRe: Managed DirectX Question. Pin
cvetant24-Jan-06 11:46
cvetant24-Jan-06 11:46 
QuestionSerialization Question Pin
LighthouseJ24-Jan-06 8:39
LighthouseJ24-Jan-06 8:39 
AnswerRe: Serialization Question Pin
Le centriste24-Jan-06 9:59
Le centriste24-Jan-06 9:59 
GeneralRe: Serialization Question Pin
LighthouseJ24-Jan-06 10:11
LighthouseJ24-Jan-06 10:11 
GeneralRe: Serialization Question Pin
Le centriste24-Jan-06 10:14
Le centriste24-Jan-06 10:14 
AnswerRe: Serialization Question Pin
tarasn24-Jan-06 10:04
tarasn24-Jan-06 10:04 
GeneralRe: Serialization Question Pin
LighthouseJ24-Jan-06 10:13
LighthouseJ24-Jan-06 10:13 
QuestionPrinting problem... Pin
Stanciu Vlad24-Jan-06 7:26
Stanciu Vlad24-Jan-06 7:26 
QuestionHow to get the previous selected index of a tab? Pin
bouli24-Jan-06 5:42
bouli24-Jan-06 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.