November 30, 2010

How to increase speed of DataGridView or using DoubleBuffered property...

A few days ago I finished developing the output window of results. It's a window similar to Visual Studio Output Window. It has a few tabs and one tab was very-very annoying. Why? Because it first performance was very low... This tab is responsible for showing all messages from external compiler what we use to compile some source. For the displaying compiler messages we used standard DataGridView component. I don't like it but his layout is that what I need. When we start our application to have real tests we were sadden. Blinking, flicker, pulling... It was the terrible to think that someone will use this dung... Google is power! But not in this situation. Every query doesn't get appropriate results. Search and search.. Nothing... Only similar troubles with no smart answers. You say I search bad.. Maybe, but in that day I don't think that. In that day power has a stackoverflow. :) Yes, yes, yes... Two minutes and I have a great answer.
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
    Type dgvType = dgv.GetType();
    PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
          BindingFlags.Instance | BindingFlags.NonPublic);
    pi.SetValue(dgv, setting, null);
}


Only one extension method to DataGridView and that's all. It's amazing..

Blinking, flicker, pulling.. No, no, no... Only smooth, clarity, speed... All what we need.

And only one question stay in my head. Why "DoubleBuffered" property is hidden? Maybe when whe set it to the true our application eats all RAM memory? Maybe our Duo Core Processors will work to the 100% to render data.. Hm.. Practical experience shown that with memory is all right (a little more, but a little) and with processor too.

MSDN says that this property indicating whether this control should redraw its surface using a secondary buffer to reduce or prevent flicker.

October 13, 2010

Express Review of Expression Trees

Yesterday I spoke about the Expression Trees. I must admit that haven't practice with this pretty feature in C#3.0. But after several blogs and msdn info I can tell that this is powerful technology which allows us to create a dynamic scenarios in our programs. To work with expression trees user must has a basic knowlages of lambda expression and understand what is a tree. Calculations in the tree are moves from the leafs to the root of tree. Miscrosoft provides a 56 different actions to use in Expressions. There are Add, Bind, Block, Break, Call, Catch, Coalesce, Continue, Equal, GreaterThan, Lambda, Loop, New, Or , PowerAssign and other.. Expression class has a several derived class such as BinaryExpression, BlockExpression, ConditionalExpression, ConstantExpression, DynamicExpression and other, which separate expression by their type. It is necessary to say that every node in the tree is an expression. Digits or Strings are also expression, to be exact there is an Expression.Constant.
Everybody who works with expression trees must be very attentive. It's too lightly to make some mistake when constuct trees. For example if you write
Expression.Add( Expression.Constant( 2 ), Expression.Constant( 3 ) ); 
 it's correct and represent a (2+3) expression, but the next code will take a runtime exception "The binary operator Add is not defined for the types 'System.String' and 'System.String'."

Expression.Add( Expression.Constant( "ab" ), Expression.Constant( "cd" ) );
It's one of the many cases when successful compilation isn't a successfull execution of the program.
 
Expression trees
View more presentations from Yuriy Seniuk.

Good luck! Try yourself with expression!

October 7, 2010

Plan your time!

Life is too short to live idly...
Чи задавали ви собі коли-небудь запитання скільки часу ви проводите в день нічого не роблячи? Це запитання я задав собі і був вкрай не задоволений своєю відповіддю. Щонайменше 2 години на день я б'ю байдики. Здавалося б 2 години, хіба це багато? Якщо взяти до уваги, що дома містить 24год., з них 7год. йде на сон, 8год. займає робота, 1год. добирання туди і назад, нехай ще 2год. на сніданок, обід та вечерю і залишається 6годин. Отже, 2 години із 6-ти (більш менш вільних) у мене виходить нічого не робити.. 33%. мого часу.
Але як добитися більш продуктивного використання часу? Планування - ось, що нам потрібно.  

  1. Сплануйте свій день заздалегідь. Використайте для цього записник, мобільний телефон із нагадуваннями (я використовую свій HTC P5500), запам'ятовувати я б не став, всеодно щось вилетить з голови, з'являться нові плани, які не дадуть реалізувати уже поставлені. Дуже класно, коли таски, розплановані також по вагомості. Спочатку високо приоритетні, потім менші, потім ще менш вагомі, ітд. Таким чином, щось менш вагоме ззувається на кінець дня, і уже не потрібно хвилюватися, що ви не встигли зробити щось важливе. Особисто в мене будуються плани над якими не потрібно працювати фізично,.. а це зле.. фізична праця не тільки підтримує здоровий спосіб життя, але й допомає розрядитися, відпочити (як це не дивно звучить) від розумової праці. 
  2. Перегляньте години, які використовуєте щоб добратися на роботу/додому. Скачайте цікаву аудіо книжку (я слухаю подкасти), та прослуховуйте її.. Позитив :).. довга й завчена поїздка на роботу перетворилася на миттєву, корисну і цікаву..
  3. Чайок.. Як багато в цьому слові.. Можна потриндіти про щось, послухати байки.. Використайте його в свою користь... подумайте, що б ви хотіли взнати нового і корисного для Вас, та задайте це запитання... Зекономите купу часу на пошук і перечитування інфи..
  4. Шукайте - Знаходьте - Використовуйте вільний час!
Що ж виходить, що можна використати 120% свого часу корисно, чому 120%? Бо використавши ваших 6 вільних годин ви неодмінно знайдете прогалини часу в повсякденній роботі, яка б, здавалося, займає ну ду-у-у-у-же багато часу.. :)

Не марнуємо часу, до діла :)

P.S. а скільки часу займає і-нет?

September 27, 2010

Lambda Expressions

Now I'm finished work at my presentation about Lambda Expressions. You can find here a list of examples how to use Lambda Expressions in your life.I hope that this material will be useful. Look and enjoy!

September 17, 2010

Hello world!

Today I'm start my blog. The first traditional post is about why I'm began this? I have several reason to write the blog.. The first is that I'm grown in IT and see that my vote is weighty for peoples... Also I wan't to write interesting and useful for you, want to improve my little knowledges in English, want to find partners to embody ideas!
Usually my posts will be about .Net, C#.. but I don't except that I'll write about something else :) Life is more than one C#.
Lets make our life colourful!