Click here to Skip to main content
16,009,847 members
Home / Discussions / C#
   

C#

 
QuestionOverride inherited delegates??? Pin
lsugirljte23-Oct-06 4:36
lsugirljte23-Oct-06 4:36 
AnswerRe: Override inherited delegates??? Pin
led mike23-Oct-06 5:17
led mike23-Oct-06 5:17 
GeneralRe: Override inherited delegates??? Pin
lsugirljte23-Oct-06 5:34
lsugirljte23-Oct-06 5:34 
AnswerRe: Override inherited delegates??? Pin
S. Senthil Kumar23-Oct-06 8:09
S. Senthil Kumar23-Oct-06 8:09 
AnswerRe: Override inherited delegates??? Pin
lsugirljte23-Oct-06 11:23
lsugirljte23-Oct-06 11:23 
QuestionGenerics: Is there a Synchronized Hashtable equivalent??? Pin
LongRange.Shooter23-Oct-06 4:08
LongRange.Shooter23-Oct-06 4:08 
AnswerRe: Generics: Is there a Synchronized Hashtable equivalent??? Pin
ednrgc23-Oct-06 4:18
ednrgc23-Oct-06 4:18 
GeneralRe: Generics: Is there a Synchronized Hashtable equivalent??? Pin
LongRange.Shooter23-Oct-06 6:55
LongRange.Shooter23-Oct-06 6:55 
Thanks. I'm not sure if your code is what I ended up with....but I used it as a basis for creating this (comments were pulled to keep my sanity with all of the lt/gt symbols) ::
using System;
using System.Collections.Generic;
using System.Collections;

namespace System.Collections.Generic
{
	/// <summary>
	/// Provides a synchronized dictionary whose instance implementation is thread safe.
	/// <summary>

	public class ThreadSafeDictionary<TKey, TValue> : IDictionary<TKey, TValue>
	{
		private readonly object syncRoot = new object();

		private Dictionary<TKey, TValue> d = new Dictionary<TKey, TValue>();

		#region IDictionary<TKey,TValue> Members

		public void Add( TKey key, TValue value )
		{
			lock ( syncRoot )
			{
				d.Add( key, value );
			}
		}

		public bool ContainsKey( TKey key )
		{
			lock ( syncRoot )
			{
				return d.ContainsKey( key );
			}
		}

		public ICollection<TKey> Keys
		{
			get
			{
				lock ( syncRoot )
				{
					return d.Keys;
				}
			}
		}

		public bool Remove( TKey key )
		{
			lock ( syncRoot )
			{
				return d.Remove( key );
			}
		}

		public bool TryGetValue( TKey key, out TValue value )
		{
			lock ( syncRoot )
			{
				return d.TryGetValue( key, out value );
			}
		}

		public ICollection<TValue> Values
		{
			get
			{
				lock ( syncRoot )
				{
					return d.Values;
				}
			}
		}

		public TValue this[ TKey key ]
		{
			get
			{
				lock ( syncRoot )
				{
					return d[ key ];
				}
			}
			set
			{
				lock ( syncRoot )
				{
					d[ key ] = value;
				}
			}
		}

		#endregion

		#region ICollection<KeyValuePair<TKey,TValue>> Members


		public void Add( KeyValuePair<TKey, TValue> item )
		{
			lock ( syncRoot )
			{
				if ( d.ContainsKey( item.Key ) )
					throw new InvalidOperationException( String.Format( "The item for key {0} already exists in the dictionary.", item.Key ) );
				d.Add( item.Key, item.Value );
			}
		}

		public void Clear()
		{
			lock ( syncRoot )
			{
				d.Clear();
			}
		}

		public bool Contains( KeyValuePair<TKey, TValue> item )
		{
			lock ( syncRoot )
			{
				return ( ( ICollection<KeyValuePair<TKey, TValue>> )d ).Contains( item );
			}
		}

		public void CopyTo( KeyValuePair<TKey, TValue>[] array, int arrayIndex )
		{
			lock ( syncRoot )
			{
				( ( ICollection<KeyValuePair<TKey, TValue>> )d ).CopyTo( array, arrayIndex );
			}
		}

		public int Count
		{
			get { return d.Count; }
		}

		public bool IsReadOnly
		{
			get { return false; }
		}

		public bool Remove( KeyValuePair<TKey, TValue> item )
		{
			lock ( syncRoot )
			{
				return ( ( ICollection<KeyValuePair<TKey, TValue>> )d ).Remove( item );
			}
		}

		#endregion

		#region IEnumerable<KeyValuePair<TKey,TValue>> Members

		public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
		{
			return ( ( IEnumerator<KeyValuePair<TKey, TValue>> )d );
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator()
		{
			return ( ( System.Collections.IEnumerable )d ).GetEnumerator();
		}

		#endregion
	}
}

Questionhow to Export DataGridView to excel in c# 2005 ? Pin
hdv21223-Oct-06 3:08
hdv21223-Oct-06 3:08 
QuestionRemoting Question Pin
Inkyskin_UK23-Oct-06 2:28
Inkyskin_UK23-Oct-06 2:28 
AnswerRe: Remoting Question Pin
LongRange.Shooter23-Oct-06 4:05
LongRange.Shooter23-Oct-06 4:05 
GeneralRe: Remoting Question Pin
Inkyskin_UK23-Oct-06 4:14
Inkyskin_UK23-Oct-06 4:14 
GeneralRe: Remoting Question Pin
LongRange.Shooter23-Oct-06 9:49
LongRange.Shooter23-Oct-06 9:49 
QuestionWndProc : on windows command ? Pin
vincent3123-Oct-06 2:22
vincent3123-Oct-06 2:22 
AnswerRe: WndProc : on windows command ? Pin
Ed.Poore23-Oct-06 4:04
Ed.Poore23-Oct-06 4:04 
AnswerRe: WndProc : on windows command ? Pin
Dave Kreskowiak23-Oct-06 4:21
mveDave Kreskowiak23-Oct-06 4:21 
QuestionRe: WndProc : on windows command ? Pin
vincent3123-Oct-06 4:37
vincent3123-Oct-06 4:37 
AnswerRe: WndProc : on windows command ? Pin
S. Senthil Kumar23-Oct-06 8:26
S. Senthil Kumar23-Oct-06 8:26 
QuestionRe: WndProc : on windows command ? Pin
vincent3124-Oct-06 3:43
vincent3124-Oct-06 3:43 
AnswerRe: WndProc : on windows command ? Pin
duanvinait25-Jan-21 20:13
duanvinait25-Jan-21 20:13 
Questionasynchrounous web methgod call Pin
Thakur Vikas23-Oct-06 1:54
Thakur Vikas23-Oct-06 1:54 
AnswerRe: asynchrounous web methgod call Pin
Stefan Troschuetz23-Oct-06 3:06
Stefan Troschuetz23-Oct-06 3:06 
QuestionCalling a Method with a Variable as its Name Pin
Gareth H23-Oct-06 1:31
Gareth H23-Oct-06 1:31 
AnswerRe: Calling a Method with a Variable as its Name Pin
Robert Rohde23-Oct-06 1:39
Robert Rohde23-Oct-06 1:39 
GeneralRe: Calling a Method with a Variable as its Name Pin
Gareth H23-Oct-06 2:46
Gareth H23-Oct-06 2:46 

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.