Thursday, August 31, 2006

Changing Text on SplitContainer, what an interesting idea....

Today I rummaged through thousands lines of C# GUI code to find out why some things happen and some things didnt. Suddenly I see (through content assist) that one of the project specific controls has a TextChanged event. This control has nothing to do with text so it directly grabbed my attention.

Then I find out that it really isnt the specific control that implements the event, it is a control further up in the hiearchy. I keep going up the inheritance tree, to find that System.Windows.Forms.Control has a property named Text (and a bunch of events for text manipulations). That is odd I think, why would a base Control class have a text property when the deriving classes are not necessary text orientated controls.
  • What happens if I change the Text property on a PictureBox? Would it show the text on top of the picture?
  • What happens if I do it on a SplitContainer?
  • Or on a NumericUpDown control?
This is one of the problems with the .NET framework. It carries to much bagage from C++ and VB into the C# (and .NET) world. The old MFC libraries probably had a SetText() method, so therefore it must exist one in .NET. I wonder why they would have such functionality, and the only idea I can come up with is: It is simple if all text specific properties are named the same, and thus every control should have one. "If we keep it in Control, then we dont have to write code for text handling in every control". But what about all those controls that dont have a text in them? They must override this property and do nothing, so now we have code that hides other code just to remove a functionality. This does not make sense to me.

The MSDN will of course answer the question if the Text property actually works or not. On those controls that do not support them, it will say "This property supports the .NET Framework infrastructure and is not intended to be used directly from your code.". Sheeesh, that makes we want to think twice before using the Text property on a Label or Button. Perhaps the Text property is not intended to be used directly in my code on a button? The best explaination is (of course all these overriden properties have different wording) "The Text has no affect on the appearance of the NumericUpDown control; therefore, it is hidden in the designer and from IntelliSense.".. I would like to see that code in the IntelliSense.

doPopupMenu(Control)
if (control is SplitContainer) || (control is NumbericUpDown)
{
menu.removeTextProperty()
}




Or is there any valid reason that every Control has a Text property?

Friday, August 25, 2006

Nant is definetly not Ant (build MSBuild is)

As a newly born .NET/C# developer, I have trouble finding those must-have-tools. At my current job, they are running VS2005 in a huge system with over 70 seperate components/solution files with each having around 2000-10000 LOC. This gives me a huge headache as it takes forever to build, and everything is built with batch files. (so 90-ish)

But as a java developer, I have come to love Ant. There is a .NET version of it called NANT that I downloaded and was going to test and hopefully replace the batch files. 10 mins after downloading I stumble into the first problem. NANT does not support (as of 25 aug 2006) Visual Studio 2005. NANT can not handle the new solution files as they have change completly (not surprisingly). Apparently it is quite a job to add VS2005 support, so it seems that it is not going to happen. So NANT is definetly not ant, as it will probably cease to be used.

The new king of building MS code is MSBuild, which seems to be a total rip-off from Ant.

Wednesday, August 16, 2006

Its 2006 and MS has still learned nothing about installations!?

Due to a contractor job, I need to get some Visual C#/.NET/MSSQL experience. So I was going to install Visual C# Express (or as it is called Visual Studio 8, or other). I got the 3 mb installation file and started the installation (I hoped). The installation program did what they always do, Greetings&Saluations, Accept eula, Install MSDN and MSSQL?. Sure I could go for those as well. The program told me that I needed 1.7++ GBs of hard drive for this installation. Fine, I have plenty of space on my D-drive (data&Programs), which I told the program.

But wait a minute! That isnt how Ms wants it!

If I choose to install everything onto the d-drive, it would install 60 MBs on the D-drive and a whooping 1.7 GBs on the C-drive. But I thought I told VS to install on the d-drive and not onto the c-drive. Of course, I understand that VS requires some files to be installed on the c-drive. But 1.7 GBs, that is ridiculos.

Ok, regroup. Lets just choose the VSC# package, and I still want to install on the d-drive. Now it still wants to install 60 MBs on the d-drive and only 314 MBs on the c-drive.

When I left the MS development environment for six years ago, they still had this idea that I as a user shouldnt be allowed to make decisions like this. Still, they order me around and forces me to install everything on the c-drive. (The c-drive is already packed as every other program/driver wants to install onto the c-drive). I guess I can solve this the MS-user way, do a re-install every two years.

At least with Java, I'm old enough to choose where to put things.

Thursday, September 22, 2005

Streamlining the debian/linux boot

As my ever continuing project is to build a media box running debian and Freevo. As of now, it can play movies, music and show images. The only big step left is to minimize the boot time for linux. For a media box that only purpose is to show movies, it must start very quickly. I need to get the boot time down to at most 30 seconds. Now it takes approx 90 seconds to boot from the grub menu. That is way to long time, so I need a few tools to get it even shorter.


I found a nice application that can show me the boot flow as a chart. This debian package can be installed from the unstable package set.


The first time I use it, I could see that it took 80 seconds to boot, and that it was the 'udev' module that took some of its time. As can be seen here. Nice graph, but what do I do with it?


Continuing searching I found another init module for linux, that promised a very faster boot time. Its called initng. Installing the package from the experiment package set, and running bootchart with it; seemed to give a much better boot time. As can be seen here. According to bootchart it would only take 14 seconds, if it only was true. USing a stoptimer, the boot takes 67 seconds. Where did those extra seconds come from? I have no clue.

Wednesday, February 09, 2005

Using MFC and threads, dazzled and amazed!?

As always Im amazed on how much worse it is by developing applications in MFC than using Swing. MFC has a complete different view of how a dialog and threads should cooperate. In short words, MFC wont let any threads to change any control in a dialog. WTF? If you have a task that takes hours, and you want to have a GUI that displays the progress of it; what do you do? The thread is not allowed to use any of the GUI controls at all, and if you do, then suddenly the whole application will lock up because you try to change a control. In Swing you dont have this problem, because you have true VMC modelling.


So what do you do when you want to update a GUI from a thread. There are two ways in MFC: you can either change the GUI control youself, but this will result in deadlocks 100% guarantee; you can either change the value (string/dword) behind the control and then call the UpdateData() method. But something that they forgot to say is that you cant call UpdateData() from a thread outside the GUI loop, doing that will result in deadlock 100% guarantee. MS only response is "threads are not allowed to touch GUI, you must send a message to the dialog that you want to update". Fair enough, but MS has failed to give such a functionality and if I want to update a tabbed dialog with data from the thread, there is no way but to implement a WM_USER message listener for every dialog that you want to update from the thread. Sheeeesh, I dont want to put more stuff into each one of the dialogs, for just make it "thread-safe" for the MFC GUI.


My solution to this problem is jsut to create a base CDialog class that will handle this problem, and is safe to update all values in a dialog. It took med 5 minutes to create it and test it. Whoah, that was easy, but that main point is IF IT WAS SO EASY, WHY HASNT MS DONE THIS IN THE FIRST PLACE? Why do I have to live with crap design eons after the MFC was "designed", why can't they extend the dialog class with such functionality so you dont have to sit and wonder why the application has locked. "Is it me or MFC?"


Im still amazed that MFC is still not thread safe, it was earlier one of the most commonly used application tools/API for creating applications. How could it survive for such a long time??


My solution, is as easy as pie. Here it is:

#include

#include



class CRefreshDialog : public CDialog

{

public:

CRefreshDialog(UINT nIDTemplate,CWnd* pParentWnd = NULL );

virtual ~CRefreshDialog();

virtual BOOL OnWndMsg( UINT message,WPARAM wParam, LPARAM lParam, LRESULT* pResult );



void RefreshDialog();

private:

CCriticalSection refreshMutex;

};





#define WM_REFRESH WM_USER + 0x9283



CRefreshDialog::CRefreshDialog(UINT nIDTemplate, CWnd* pParentWnd ) : CDialog(nIDTemplate, pParentWnd)

{

}



CRefreshDialog::~CRefreshDialog()

{

}



BOOL CRefreshDialog::OnWndMsg( UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult )

{

BOOL wasHandled = FALSE;

if (message == WM_REFRESH)

{

UpdateData(FALSE);

} else

{

wasHandled = CDialog::OnWndMsg(message, wParam, lParam, pResult);

}

return wasHandled;

}



void CRefreshDialog::RefreshDialog()

{

CSingleLock lock(&refreshMutex);

lock.Lock();

::PostMessage(m_hWnd, WM_REFRESH, 0, 0);

lock.Unlock();

}