GVNotifier tutorial video

January 22, 2010 by Dave · Leave a Comment
Filed under: Uncategorized 

Here’s a great video that gives an overview of GVNotifier’s features.

If you can’t see the video, try here.

C# Threading Shorthand

January 22, 2010 by Dave · Leave a Comment
Filed under: Code Snippets 

As the complexity of an application increases, often so does the threading complication.  I have two snippets which often come in useful when dealing with threads in C#.

Quickly execute code in the background:

new Thread((ThreadStart)delegate()
    {
        // code here is executed on a new thread
        // blocking operations will not block the calling thread
    }).Start();

Note that if this code is to be called often, a ThreadPool may be the better choice. ThreadPools’ have less overhead for instances when many threads would be created and destroyed.

Execute code that manipulates UI:

if (Control.IsHandleCreated)
{
   Control.Invoke((MethodInvoker)delegate()
   {
        // code here is safe to interact with Control
   });
}

Replace ‘Control’ with ‘this’ inside the Form class. Control may refer to any control created on the UI thread.

Search Urban Dictionary with C#

January 22, 2010 by Dave · Leave a Comment
Filed under: Code Snippets 

Here’s a quick example of how one might scrape the search results from Urban Dictionary.  This shows some nice use of Regular Expressions and WebClient.

(View Text)

Thankfully Urban Dictionary is a very scrape-friendly site, finding results is as easy as locating two div’s and extracting the contents.

UrbanDictionary.Search(string); will return a list of key-value pairs which contain the word as the key, and the Urban Dictionary definition as the value.

WhosOnline has been deprecated

January 17, 2010 by Dave · 1 Comment
Filed under: Thoughts 

WhosOnline was an application that would scour the offline buddies of an AIM screename and attempt to discover those which were invisible. This software is long since non-working.

WhosOnline used a simple bug in AIM that would allow the presence information of someone invisible to be available through their profile.  Simply requesting the profile and examining the response would allow one to determine whether someone was invisible or offline.

AOL has long since patched this bug, and WhosOnline is no more.  There is no available download–but it wouldn’t discover invisible buddies anyway.  This website is linked to, and I receive many requests for this application, but it simply doesn’t exist anymore.

TraceListener to a textbox

January 16, 2010 by Dave · Leave a Comment
Filed under: Code Snippets 

Trace, in System.Diagnostics is useful for determining where an application failed. .NET has build-in support for writing to the console or a file on disk, but it’s a little bit more complicated to direct this output to a TextBox on a windows form.

Here’s the class you need to get the trace information.

    class FormTracer : TraceListener
    {
        public delegate void OnTextHandler(string msg, bool newLine);
        public event OnTextHandler OnText;
 
        public override void Write(string message)
        {
            if (OnText != null)
                OnText.Invoke(message, false);
        }
 
        public override void WriteLine(string message)
        {
            if (OnText != null)
                OnText.Invoke(message, true);
        }
 
        public FormTracer()
        {
            Trace.Listeners.Add(this);
        }
 
         ~FormTracer()
        {
            Trace.Listeners.Remove(this);
        }
    }

When created, FormTracer will add itself to the tracers collection and start receiving messages. To add these messages to your form, create a FormTracer object like so:

        public Form1()
        {
            InitializeComponent();
 
            FormTracer ft = new FormTracer();
            ft.OnText += new FormTracer.OnTextHandler(ft_OnText);
        }

The event handler may be called on threads outside the UI, so you’ll want to make the OnText handler look something like this

        void ft_OnText(string msg, bool newLine)
        {
            if (this.IsHandleCreated)
            {
                this.Invoke((MethodInvoker)delegate()
                {
                    textBox1.Text += msg;
                    if (newLine) textBox1.Text += "\r\n";
                });
            }
        }

Add a button and handle the Click event for a test Trace message.

          private void button1_Click(object sender, EventArgs e)
        {
            Trace.WriteLine("Button Pressed!");
        }

GVNotifier 1.1.0.110

January 8, 2010 by Dave · 4 Comments
Filed under: Software 

Small release today, including a few bugfixes.

- Duplicate protection – this option only needs to be used if constant duplicate messages are seen.

- Show accepted calls – added an option for this feed.

- various other updates.