Monday, December 24, 2007

New experience in C#

During last week I was doing rather interesting work: programming on C# my own Windows control similar to TextBox class. I was programming a text editor and needed to make color syntax. But RichTextBox allows to change color and other properties only for selected text, that isn't good. So I've decided to try to make my own control to work with text. Now it is rather good and implements some common functions. The most important is that I've understand that this is *really* possible, not only on paper. And through developing this control I've experience many difficulties. So now I want to write something like "How to make TextEditorControl on C#". Of course not on a professional level but I think I need to write down all this experience, while it fresh in my mind. So in future it will be easier for me to implement similar things. Moreover while writing I will unconsciously analyze what I'm writing and may be will get better solutions or completely new ideas.

Furthermore I want to write similar article about making tool to explore .NET assemblies using reflections. I already have basic implementation of such a tool and it need more polishing.

Bye.

Sunday, December 09, 2007

Funny Bug in Visual Studio 2008 Beta

While uninstalling MS Visual Studio 2008 Beta 2 I found one funny bug.



Trivial message from uninstaller that indicates that one or more of the files or directories to remove are occupied. The only thing to do is too close this application and click Retry. If this doesn't help, well click Ignore and hope this will not have any negative effect. But... what the heck is application named 4812? Well, it's may be not a name but an ID of process so I open Task Manager and look up for a process with ID 4812. Here it is!



Oops. It is a setup application itself blocked something and couldn't delete it. I tried to click "Retry". And it was a successful attempt process of uninstaller continued.

I even could make a guess why this short story happened but had a good final. While checking files/directories to remove setup.exe locked them. According to my guess releasing of lock is placed in destructor. When message appeared object that locked files was "deleted" but garbage collector wasn't called until that moment so hadn't called destructor. While I was thinking about this problem and taking screenshots garbage collector was invoked and called destructor that released locks. Of course this guess can be true only if setup.exe is using garbage collector. Well, as Andrew Troelsen in his book about C# suggested it is better to manually call method Dispose and release all resources when they already could be released and don't leave this job to GC, which is unpredictable.

Of course my suggestion is only a suggestion, but I think it is rather useful to try to explain bugs in not your applications even if source code is inaccessible.

Wednesday, December 05, 2007

The Dialog with Myself

I've already written that what I want to change in myself. Surely it's not easily to change myself (at least for me). And I think that to put off bad habit may I need to have split personality in some way. And one of that personalities must say "That is bad, don't do it" when it is needed. May be this should be something like fight between good and evil, though I'm not sured that someone in me is really good or evil. May be both of them should help each other. There must be a dialog inside of person, dialog with himself. But how to speak with myself? The most obvious way for is to have to "Me's". May be this a psycho disease? But to learn on fault your need to have someone who will point on them, and nobody as you can now what you do and why you do.

Visual Studio 2008

In the end of November MS released the new version of its IDE Visual Studio 2008. I've used Beta version already. It that post I've written that first impression was that is is very buggy, and later practice showed that there are some mistakes. I usually had some problems with Intellisense and IDE crashed. I have to note that I used Professional Edition.

Now I'm using Express Edition. I'm not so rich to buy IDE now, so use free edition. Of course it's not so functional as Pro version and for each language (C#, C++, VB.NET, Web development) there is it's own IDE. However I'm currently programming only on C# so this is not a big problem for me. Visual Studio is rather comfortable IDE (especially comparing to Turbo C we have in unversity :(. The problem is that it can't be used for editing all types of files I need with syntax coloring. So for editing files such as Nullsoft installation scripts, Python files and others I use PSPad. But for C# Visual Studio is much more preferable because autocompletion, Intellisense and many other small but very useful features.

One interesting note about Visual Studio: with IDE many other components are installed (SQL Server Compact, etc.). But uninstalling them is a manual operation. Not rather comfortable.

I have to say that Visual Studio is one of my favorite MS products and I haven't a lot of complains about it.