К основному контенту

Сообщения

Dispose pattern to file reading in C#:

This is how to implement dispose pattern to file reading in C#: using System; using System.IO; class BaseResource: IDisposable { // Track whether Dispose has been called. private bool disposed = false; // The unmanaged resource wrapper object private FileStream file; // Class constructor public BaseResource(String fileName) { Console.WriteLine("BaseResource constructor allocates unmanaged resource wrapper"); file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); } // Implement IDisposable public void Dispose() { // Check to see if Dispose has already been called. if (!disposed) { Console.WriteLine("Dispose pattern releases unmanaged resource wrapper's resource"); file.Close(); disposed = true; } } public void Close() { Dispose(); } public void DoS
Недавние сообщения

Today I've brought together with no way to insert item in Many-to-Many relationship based on Entity Framework

The decision was unexpected. I've missed to mark my primary keys in the intermediate table. That was all... Be carefull! http://weblogs.asp.net/kencox/archive/2009/09/09/fixing-the-system-data-updateexception-definingquery-and-no-lt-insertfunction-gt-error.aspx

Implementing Singleton in C# (Применение Одиночки в C#)

You are building an application in C#. You need a class that has only one instance, and you need to provide a global point of access to the instance. You want to be sure that your solution is efficient and that it takes advantage of the Microsoft .NET common language runtime features. You may also want to make sure that your solution is thread safe. Implementation Strategy Even though Singleton is a comparatively simple pattern, there are various tradeoffs and options, depending upon the implementation. The following is a series of implementation strategies with a discussion of their strengths and weaknesses. Singleton The following implementation of the Singleton design pattern follows the solution presented in Design Patterns: Elements of Reusable Object-Oriented Software [Gamma95] but modifies it to take advantage of language features available in C#, such as properties: using System; public class Singleton { private static Singleton instance; private Singleton

Выпущена новая версия Kinect for Windows SDK, новый сайт и блог для разработчиков

Выпущена новая версия Kinect for Windows SDK, новый сайт и блог для разработчиков Если дойдут руки - обязательно попробую)

Catastrophic backtracking в регулярных выражениях

Можно ли простой и вроде невинной регуляркой убить систему? Да, можно. Например: >>> r = '(a+)*b' Просто — да. Невинно — вроде да. Конечно неумно, потому что скобки и звездочка лишние, но должно работать. Попробуем: >>> re.findall('(a+)*b', 'aaaaaab') ['aaaaaa'] Круто, работает, пошли пить пиво. А нет… Если строка, в которой ищем, не будет содержать искомого паттерна, например просто 'aaaaaa', компилятор будет пробовать найти её следующим алгоритмом: 1. Вся стока удовлетворяет 'a+', но мы не находим 'b', шаг назад. 2. Теперь 'a+' удовлетворяет только 'aaaaa' (все, кроме последней), последняя удовлетворяет повтору '*', 'b' все равно не находим, шаг назад. 3. Первое 'a+' удовлетворяет только 'aaaa', последние два 'aa' удовлетворяют повтору '*', 'b' все равно не находим, шаг назад. 4. Первое 'a+' удовлетворяет 'aa

Four Destructive Myths Most Companies Still Live By

Myth #1: Multitasking is critical in a world of infinite demand. This myth is based on the assumption that human beings are capable of doing two cognitive tasks at the same time. We're not. Instead, we learn to move rapidly between tasks. When we're doing one, we're actually not even aware of the other. If you're on a conference call, for example, and you turn your attention to an incoming email, you're missing what's happening on the call as long as you're checking your email. Equally important, you're incurring something called "switching time." That's the time it takes to shift from one cognitive activity to another. On average, according to researcher David Meyer, switching time increases the amount of time it takes to finish the primary task you were working on by an average of 25 percent. In short, juggling activities is incredibly inefficient. Difficult as it is to focus in the face of the endless distractions we all now face