The Developer Stash

Arbitrary Contemplations
posts - 20, comments - 29, trackbacks - 0

My Links

News




Locations of visitors to this page

 





Elroy D'silva's Blog

Twitter












Archives

Post Categories

Blogs I read

Tuesday, November 04, 2008

Personalize your application executable

You've written programs and created executables, and also probably distributed them. But, it would feel strange to pass on your .EXE as just-another-exe. Windows provides a default executable icon to your generated output EXE file which looks something like this:



Well, there's nothing wrong in having such an icon for your executable file. But, the hard work who put in in implementing the functionality within the EXE certainly deserves some credit and possibly a custom designed icon.

Lets see how we can do this. It's fairly simple. Once you're done with the coding stuff and you're ready to build your exe for release, go to the Project Properties -> Application tab -> Resources Group. Here, you will find the Icon and manifest radio button, select it and select the icon you need to use for your adorable application.



Please note that the above screenshot is the Project Properties tab for VS 2008 and it would look slightly different from the one you would see in VS 2005.

You now build the application and have a look at the generated executable which would look something like:



I created this icon by adding a resource (.resx) file to my project and then adding an icon to that resource file. Scribbled a bit using an MS Paint kind of pencil and here we go, I have a brand new icon (looks familiar, something like an inverse of Red Cross, but I could only think of this one right now).

posted @ Tuesday, November 04, 2008 10:17 PM | Feedback (1) |

C# 3.0 for Beginners - Query Execution in LINQ

       The execution of queries written is different from what a new LINQ user would perceive it to be. The query isn’t evaluated and the result is not stored in the query variable until the foreach iteration (where the values are actually required) or a manual iteration using the underlying GetEnumerator and MoveNext methods. The query variable only stores the query commands. This is concept is referred to as deferred execution.


public static void GetIExplorer()
{
    //  1. Data Source
    Process[] processes = Process.GetProcesses();
 
    //  2. Query Creation
    IEnumerable<int> query =
       from p in processes
where p.ProcessName.ToLower().Equals("iexplore")
select p.Id;
 
    //  3. Query execution
    //  This is the part where the query is evaluated
    //  and result is stored in the query variable.
    foreach (int pid in query)
    {
        Console.WriteLine("Process Id : "+pid);
    }
}

 

As the query variable doesn’t store the results, you can execute it as many times as you like. If a data source is updated at regular intervals, you could retrieve the latest results every time you iterate over the query variable.

Deferred execution

The figure shown above shows information about the query variable ‘query’. The Results View section shows the results of query execution and it also informs the user that “Expanding the Results View will enumerate the IEnumerable” i.e. perform the query execution for debugging.


Forcing immediate execution of queries
    Immediate execution of queries is forced for queries that perform aggregation functions over the data retrieved from query evaluation. These functions include Count, Max, Min, Average etc. These queries execute without an explicit foreach statement because the query itself would use a foreach statement to calculate the result.

The following query returns the number of processes identified as “IExplore.exe”.

 

//  Calculate the number of "iexplore" processes
int numberOfProcesses = query.Count();


Execution results can be cached (if need be) for temporary processing using the ToList() and ToArray() methods as shown below:

 

//  Caching results using ToList() and ToArray() methods.
List<int> queryResult =
(from p in processes
 where p.ProcessName.ToLower().Equals("iexplore")
 select p.Id).ToList();
 
Array inferredQueryResult =
(from p in processes
 where p.ProcessName.ToLower().Equals("iexplore")
 select p.Id).ToArray();



posted @ Tuesday, November 04, 2008 8:48 PM | Feedback (0) |

Powered by: