Category Archives: Uncategorized

Upgrade of Vista to Windows 7

Well I had a wild hair thinking that I could recover some RAM usage by upgrading from my current Windows Vista Ultimate to the Windows 7 RC1 (Build 7100). Why not I figured if it blows up then I will just whack it all and re-install Vista anyhow.

My machine is a Q6600 (Quad 2.4 Ghz) with 6GB of RAM. With just Vista at a cold boot it consumes 2.2GB of RAM!;vista_64_mem_usage

I thought for sure that upgrading to the latest Windows 7 RC1 would lower the memory usage. But after the upgrade (which took about 2 hours, blah) I still have 1.25GB of RAM being used by just the OS.

One really has to wonder what the hell Windows is doing with all that friggin’ RAM. I mean seriously over a gigabyte of RAM? I dual-boot into Ubuntu 9.0.4 and its using 250MB of RAM to the desktop. Really makes you wonder.

TraceListener and writing to a listbox with EventHandler

So say you want to have a Trace listener setup to listen for any Trace outputs and you would like to take the Trace Write outputs and put that into a listbox.

This shows you how to setup a custom eventargs, custom TraceListner and then add the custom Trace listener to add messages received to a listbox.

Make a new custom EventArgs like this:

[code:c#]    public class EventListenerArgs : EventArgs
    {
        private string _message;

        public string Message

        {
            get { return _message; }
            set { _message = value; }
        }

        public EventListenerArgs(string Message)
        {
            this.Message = Message;
        }
    }[/code]

Then setup a custom TraceListner that implements the EventListener above like this;

[code:c#]    public class EventFiringListener : TraceListener
    {
        public event EventHandler<EventListenerArgs> WriteEvent;

        public override void WriteLine(string message)
        {
            EventHandler<EventListenerArgs> temp = WriteEvent;
            if (temp != null)
            {
                temp(this, new EventListenerArgs(message));
            }

        }

        public override void Write(string s)
        {
            EventHandler<EventListenerArgs> temp = WriteEvent;
            if (temp != null)
            {
                temp(this, new EventListenerArgs(s));
            }

        }          
    }

[/code]

Then in your form (where you have the listbox) create the custom TraceListener and add it to the TraceListener collections;

[code:c#]

EventFiringListener listener = new EventFiringListener();
listener.WriteEvent += new EventHandler<EventListenerArgs>(listener_WriteEvent);[/code]

And the method event could look like this;

[code:c#]        void listener_WriteEvent(object sender, EventListenerArgs e)
{
        this.listbox.items.add(e.Message);

}
[/code]

Enjoy!

Subsonic Delete Example

Subsonic seems to be really all that for DAL (Data Access Layer). In this example I have a table named “DvdNote” that a struct was generated by the Subsonic SubCommander tool.

Example on how to perform a delete statement;

[code:c#]                    SubSonic.Query qryDelete = new SubSonic.Query(DvdNote.Schema);
qryDelete.QueryType = SubSonic.QueryType.Delete;
qryDelete.WHERE(DvdNote.Columns.DvdnotePkid, this.Identity);

qryDelete.Execute();[/code]

Syntax highlighting, ftw! Hurrah!

Subsonic Simple Select and IDataReader Magic

Simple code snippet on using Subsonic Query for selecting data back.

[code:c#]

SubSonic.Query qry = new SubSonic.Query(Usr.Schema);
qry.SetSelectList(Usr.Columns.UserPkid);
qry.QueryType = SubSonic.QueryType.Select;
qry.AddWhere(Usr.UsernameColumn.ColumnName, SubSonic.Comparison.Equals, Username);

using (IDataReader reader = qry.ExecuteReader())
{
    while (reader.Read())
    {
        userpkid = long.Parse(reader[Usr.Columns.UserPkid].ToString());
    }
}

[/code]

Javascript Model Window Wont Fire Page_Load

I have a page that fires a popup window and in that popup window I have some logic that I need to perform in the Page_Load.

Works great the first time as the popup window gets created, the problem is each subsequent call does not fire the Page_Load event. This is because the form is still in memory and has not disposed.

So the secret to making the form go away on close code like this;

[code:c#]

        // a script to be run in client-side
        string scriptStr = “<script>window.close();</script>”;

        // send the script to output stream
        ClientScript.RegisterClientScriptBlock(typeof(string), “closing”, scriptStr);

[/code]

On the ASPX page put this as the very first line (as in line #1);

[code:html]<% Response.Expires = -1;%>[/code]

Super!

Enjoy!

Secret sauce for Nice Looking GridView

Here is the ingredients for making the Datagrid view have a nice mouse rollover to change colors.

[code:c#]

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add(“onmouseover”, “this.style.cursor=’pointer’;this.originalstyle=this.style.backgroundColor;this.style.backgroundColor=’#EEFF00′”);
        e.Row.Attributes.Add(“onmouseout”,”this.style.backgroundColor=this.originalstyle;”);
        e.Row.Attributes[“onclick”] = ClientScript.GetPostBackClientHyperlink(this.gv, “Select$” + e.Row.RowIndex);
    }
}

[/code]

So yellow when the mouse is pointing at the row then back to whatever it was before the mouse was when the mouse leaves.

 

Neat, Quick Debug to Console Output

A very easy wayt to get Debug output for your debugging purposes:

 


  • Add the ‘System.Diagnostics’ using statement to the class.
  • use the ‘Debug.WriteLine(“Batman is totally kick butt”);’ syntax to send debug signals to any listeners
  • Add a Debug listener to your tester app; 

[code:c#]TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(myWriter);
[/code]

Enjoy!