Dima's profileDima PaskoBlogListsGuestbook Tools Help

Blog


    Корректный Double Checking Locking Pattern

     

    class Singleton 
    {
        private static readonly object _locker = new object();
        private static volatile Singleton _instance = null;
    
        public static Singleton Instance
        {
    	get
    	{
    	    if( _instance == null ) 
    	    {
                    lock( _locker ) 
                        if( _instance == null ) 
                            _instance = new Singleton();
                }
                return _instance;      
            }
        }
    }

    Взято с http://blogs.byte-force.com/xor/archive/2006/01/25...

    Web Request & Security Exception

    Юзаем на хостинге:

    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(http://www.ya.ru/);

    выдает:
    Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
    Exception Details: System.Security.SecurityException: Request for the permission of type System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

    долго думали :-)
    читали Google Group
    добавили в web.config:

    <system.web>
    <trust originurl="" level="Full">
    </system.web>

    заработало!!!

    Convert IList to Generic List

            protected static List<T> ConvertToGenericList(IList listObjects)
            {
                List<T> convertedList = new List<T>(listObjects.Count);
    
                foreach (object listObject in listObjects)
                {
                    convertedList.Add((T) listObject);
                }
    
                return convertedList;
            }