Steve Hebert's Development Blog

.Steve's .Blog

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Blogs I Follow

Favorite Tools

Development Articles

Subscriptions

Post Categories

Article Categories



Friday, July 09, 2004 - Posts

RSS Bandit
I might be behind the curve on this one, but I just started using RSSBandit as my RSS Aggregator.  I really like this tool! Thanks to Roy Osherove for the link.

posted Friday, July 09, 2004 2:00 PM by sdhebert

Simplifying Thread Communication - situation specific

I have a VS.NET plug-in I created where I'm grabbing files from SourceSafe and building SQL Scripts - the order is dictated by an XML Document on the solution root.

My status dialog box shows the progress of files being processed and the actual processing is being done in a background thread.

Previously, I've always thrown a communication message to the UI window to update at the 'next most convenient time'.  Basically, I’m placing a custom message in the window’s message loop.

Here is where I changed my thinking on thread communication (for this app)...

The speed of this application’s messages are typically extremely fast and handling the overhead of posting inter-thread messages seemed to be overkill in this matter. It turns out the overhead of the messaging didn’t come close to outweighing the potential polling-cost. I simplified the code by creating a shared class that holds state information.  The worker thread’s processing object holds one reference while my UI object holds another.  I placed a timer on the UI form to trigger 10 times a second (more than enough to give the user the illusion of real-time feedback).  From the UI, I ask the state class if any messages need to be processed. This boolean check is fast and basically attempts to minimize the amount of time the UI thread is doing anything.

Performance-wise I’m very happy with it.  Turning off the UI updates when creating a 20MB script was minimally different than with them on.  The significance was so small it wouldn’t be worth considering the time to rewrite for comparison. 

Now here’s the piece I really liked...  When I’m running the command-line version of the code, I didn’t have to make changes due to the lack of UI – no ‘ifs’ on the nullness of a window object.
 
Here’s one portion of the ProcessState class I wrote.  The WorkerThread accesses the AddProcessNote while the UI thread accesses GetProcessNotes.  One optimization I’m considering is a new ProcessState class implementing the same interface that simply throws away all information sent to it (ProcessStateNoUI) because GetProcessNotes is never called.


public class ProcessState
{
   private ArrayList m_alProcessNotes = new ArrayList();

   public ArrayList GetProcessNotes()
   {
      ArrayList aList = new ArrayList();
      lock(this)
      {
         IEnumerator oEnum = m_alProcessNotes.GetEnumerator();

         while( oEnum.MoveNext() )
            aList.Add( oEnum.Current );
  
         m_alProcessNotes.Clear();
      }
     
      return aList;
   }

   public void AddProcessNote( string sNote )
   {
      lock(this)
         m_alProcessNotes.Add( sNote );
   }
}

This isn’t an optimal solution for all situations, and I’d generally say that polling is a horrendous idea in a multi-threaded app – to the point where I’d say a very good explanation better be included - which I added to the code docs.  Given the extremely limited scope of the application – I don’t feel the growth potential of the application will ever put this code in jeopardy of being a performance bottleneck.

posted Friday, July 09, 2004 12:27 PM by sdhebert

What was your first computer class? - A Friday Post

After my post on the Dec Vax users and all the comments received,  I started thinking about my first computer class.

What was your first class?  How did it go?

Here is mine:

In the fall of 1981, my parents signed me up for a computer class at the local university.  I was 11 at the time.  They had a fresh lab of IBM PC 5150 computers for us to use- dual floppy, color monitors and 16KB of RAM. The lab was great, the first program I ran on the machine was a "skyline generator" - it drew random multi-colored boxes all anchored to the bottom of the screen written in BASICA.

The teacher was a math professor at the university - his specialities were advanced calculus and removing fun from everything.  We had two rooms - one with the computers and one with desks.  You had to write your BASICA program on paper in the computerless room and prove to him it would work before you could spend any time on the machine.  He believed in holding the program's structure in your head and being able to conceptually "run" it.  That's one skill I'm glad I learned early.

Aside from the technical details, I remember a girl whose last name was Mancini.  We called her 'boom-boom' - after the fighter. Ater all, I was only 11.

I only did OK in the class - I got a C+.  But my parents bought me a home computer (first a Commodore VIC-20 and then a Commodore 64) and I've been hooked ever since. And I can proudly say I've never worked on punchcards - thank you IBM.

posted Friday, July 09, 2004 10:27 AM by sdhebert




Powered by Dot Net Junkies, by Telligent Systems