HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

“How are you spending your time on the computer?” Part 2

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
theyouryouarespendingparttimecomputerhow

Problem

In my previous question I got some pretty good suggestions which really improved the overall performance of the controls, but I decided to extend the application and add some more features :

  • You can enable/disable auto-updating.



-
You can select which processes you want to view currently available options are :

-
Default - shows all the processes.

-
Active - shows only active processes.

-
Foreground - show only foreground processes.

-
Upon minimizing the application will move to the tray bar (there is small bug there sometimes 2 icons will show, but the second will fade after few seconds.)

-
You can inspect processes, which shows 3 more additional properties :

-
Instances running - the amount of active instances of the process.

-
Process Path - the directory where the .exe is located.

-
Background Process - Indicates whether a process is background process or not (true/false).

-
Owner - the user that runs the process DOMAIN / user.

-
You can also terminate and refresh processes.

-
Searching options is available with auto suggest from the current shown list of processes.

Note

The application now requires administrator privileges as most processes are hidden if not run as administrator + it prevents most of the exceptions, tho there are few processes that will still deny access.

That pretty much sums up all the new things and this is how the program looks like now :

Let's start inspecting the code than.

BufferedListView

As suggested in the previous question's answer I'm not using a simple class that "extendeds" the ListView control by setting the DoubleBuffered property to true by default, to reduce flickering.

public sealed class BufferedListView : ListView
{
    public BufferedListView()
    {
        DoubleBuffered = true;
    }

    protected override bool DoubleBuffered { get; set; }
}


Extensions.cs

The new extension methods :

-
RemoveAll(this IDictionary) with 2 overloads, it works the same way as a `List.Rem

Solution

Just a very small review to get you started - the code looks pretty good at first glance. You have nice small functions that seem to nicely split up the work. I'm also terrible at winforms so I won't try to suggest things around that.

Your extension method ExtendWithEmptySpaces seems to be functionally equivalent to the built in method String.PadRight.

This:

lvInspectedProcess.Columns.Add("Property                   ");


Would be better as:

lvInspectedProcess.Columns.Add("Property".PadRight(27));


This bit of code jumps out as not being in the same style as the rest of it:

string query = "SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = " + process.Id;


That's for 2 reasons -

  • Explicit type when the RHS is obvious



  • string concatenation



I'd prefer it to look like:

var query = $"SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = {process.Id}";


Another very minor note is that in English, unlike some languages, the punctuation should immediately follow the last word in the sentence. That means:

MessageBox.Show(@"No process selected !");


Should be:

MessageBox.Show(@"No process selected!");


That said, I would avoid using exclamation marks in messages to users. It suggests that the program is surprised something has happened (which it isn't) but it can also seem intimidating to less technically savvy users.

Code Snippets

lvInspectedProcess.Columns.Add("Property                   ");
lvInspectedProcess.Columns.Add("Property".PadRight(27));
string query = "SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = " + process.Id;
var query = $"SELECT ExecutablePath FROM Win32_Process WHERE ProcessId = {process.Id}";
MessageBox.Show(@"No process selected !");

Context

StackExchange Code Review Q#152210, answer score: 7

Revisions (0)

No revisions yet.