Friday, November 6, 2015

C# Background Workers Using Shared Memory

It doesn't happen often in my particular coding shop, but once in a rare while the requirement for different threads in a program to use a shared memory variable rears it's head.  It really isn't difficult to handle this requirement in C#; actually, it is surprisingly easy if you are careful to avoid deadlock situations,

The key to this solution is a simple static class:

using System;
using System.Collections.Generic;
using System.Text;

namespace ThreadCom
{
    static class StaticShare
    {
        public static object MsgLock = new object(); // Functions as a lock when accessing Messages.
        public static string Messages = ""; // This is what is shared and used in all threads of this sample program.
    }
}

Basically, this snippet of C# code creates a static class with two public properties: MsgLock and Messages.  MsgLock is used to control access to Messages; a string that contains the data shared among the different threads.  Remember, performance is important; keep the shared static variable terse and small.

Here is how a thread (specifically a BackgroundWorker) might use the StaticShare class to lock, access and change the shared data without causing noticeable contention or throwing exceptions:

                lock (StaticShare.MsgLock)
                {
                    ReportProgress(0, "From " + BWName + " -> " + StaticShare.Messages);
                    StaticShare.Messages = BWName + " current time: " + DateTime.Now.ToString();
                }

The first line locks MsgLock, or causes the thread to wait until another thread's lock is released.  The ReportProgress() line is a method belonging to a BackgroundWorker, that line, in this case is accessing our shared variable Messages.  The last line in the Lock() block assigns something to the shared variable.

One big caveat here...  Make the code within the lock() block short, concise, to the point and fast.  If the code there is time-consuming or performs poorly, the lock() could cause other threads to be blocked.

Remember...  thread blocking is not cool!

You can download the entire c# project from my Google Drive here.  Standard code disclaimer: This code is for education, information and perhaps a few laughs.  It may not be perfect but does demonstrate a valid implementation of using shared storage with a multi-threaded C# application.

-whew-

Tuesday, October 27, 2015

Goodbye Facebook

Yup...  See ya later.  Apparently the fine folks at the world's most prominent social media site don't believe I am who I say I am.  Fifteen years ago, if Facebook was around, I wouldn't have blamed them one bit for being a bit suspiscious; but now???  I am ME...  really!

But not according to Facebook.  Here's what their little help page shows me...

Why was my account disabled?

Your account was disabled for violating the Facebook Terms.

Our Policies

  • Your account must list your authentic name.
  • Personal accounts must represent individual people only. It's a violation of our policies to use a personal profile to represent anything other than yourself (ex: celebrities, pets, ideas, objects, etc.).
  • Impersonating anyone or anything is not allowed.
  • Maintaining multiple accounts is a violation of our policies.
  • Accounts created for the purpose of spamming or harassing others are strictly prohibited.
(The above is from the page at https://www.facebook.com/help/245058342280723)
Well... My name on Facebook was not EXACTLY my authentic name but close.  I mean, really...  how many people use their 'authentic name' on most internet sites?  Are they saying a person with a name like 'Josephina Hope-Rosetta Kellerman-Patrinskia' must use that exact name on Facebook?  Wouldn't 'Jose Kellerman' work just as fine, so long as the person isn't trying to be deceptive?

"Personal accounts must represent individual people," they state.  What about this profile? https://www.facebook.com/phillip.cat.31

My only activities over the last year have included interacting with my daughters and one or two friends.  How often?  Hell, I only logged onto Facebook maybe once a week.  Real life is where the fun is happening!

At any rate, now the fine folks at Facebook, according to the information at (https://www.facebook.com/help/contact/183000765122339) want me to scan and upload a government ID that contains my name and date of birth or name and a photo, or two non-governmental IDs that contain my name and date of birth or name and a photo, or some combination of different IDs...  Honestly, I didn't read much past the first two options.

Sure, they do state that things like Social Security Numbers, credit card numbers, etc...  should be covered up, blurred or otherwise obscured.

Still...  Facebook...  You just aren't that important.

Saturday, July 25, 2015

Apparently This Is a 'Thing'

Confirmed...  Watching videos on YouTube of other people play video games is indeed a 'thing'.  My daughter likes Markiplier and my other daughter's boyfriend likes to watch videos from some other guy.

Seriously...  Watching other people play video games???  An activity (if one can call it that) for those techno-geeks too lazy to watch golf!

Disclaimer: I love my daughters and their boyfriends are part of our family, no doubt.  My opinion stands...  too lazy to watch golf...  sometimes.  :-)

Thursday, July 16, 2015

Where DO All The Old Programmers Go???

My wife and I just happened to be doing a little shopping together last weekend in a little fabric store.  There by the front door was a moderately sized sign that advertised their "senior discount" program.  After a few moments, it hit my brain...  One more year and I could qualify!  I mean, 5% off is 5% off, but I sure as hell don't feel or act that old.

That little sign made me wonder...  What the hell does happen to older programmers?  Well, here's a few links that might explain where they go.  (and, no...  they don't dry up and evaporate, slowly curl up into the fetal position where they spend the rest of their lives or end up in rehab clinics for the chronically caffeine addicted.)

Where do all the programmers go?

Why aren't there a lot of old programmers at software companies?

A 55-Year-Old Developer Tells Us What It's Like To Face Homelessness In A Youth-Obsessed Silicon Valley

What happens to all the "old" programmers?

I've got about 20 years before retirement age...  One thing I can say at this point in my professional life...  Programming has never been, and never will be boring.

Monday, July 13, 2015

C# Battle - Dynamic Array -versus- Generic Collection

In a previous post I insinuated that using a dynamic array in C#, rather than a dynamic structure might show a certain lack of basic programming skills.  Well, after getting my daughter off to work early Saturday morning, a storm rolled in, throwing out my plans to perform a little yard maintenance.  So...  what to do?  How about a little computer play while drinking my morning coffee.

After all, drinking coffee while practicing my guitar has far too many times caused scares due to the possibility of spilled coffee!

So, I set out to prove that Dynamic Arrays are worse performers than Collections in C#.  Well...  For my tests, my presumptions were proven incorrect.  My little test showed that when loading image bitmaps from PNG files into a Dynamic Array, there is only a marginal difference loading into a C# Collection.

Machine Baseline...
CPU: Intel Core i3-3240 @ 3.4 GHz
RAM: 8GB
Windows Version: 7 Ultimate 64 bit.
Hard Drive: ADATA SP920 512MB SSD drive
Number of images to load: 9727
Image size: All are 640 x 480

Read on for the code and specific results...

Saturday, July 11, 2015

Basic Skills, Please People!

Please!!!

Programmers really should know the basics of a language and platform before coding something that is used in a production environment.  Knowing the cool tricks of a language is nice but not knowing how the basics work is just irritating.

Take for instance a little optimization I just finished...  A SQL query was returning about 800,000 rows where about 799,700 were duplicates.  Adding a distinct to the SQL made the page load about 80% faster.  Why did the programmer not use that distinct keyword???  Maybe because they didn't know the basics.  Maybe because the programmer was sloppy.  Maybe the programmer didn't completely understand what was requested.  Don't know.

Then, while looking at the rest of the code I saw several string arrays defined; arrays that, after populated, contained hundreds of items.  To build these arrays, Array.Resize was used to add items.  Now THAT just might be inefficient.  Array.Resize copies the entire array and adds another element.  The programmer probably should have used a List<> or some other dynamic structure.

Hmmm...  now I am curious...

Friday, July 10, 2015

Early Beer Friday

So, it's Friday...  How do you know this day is just right for an early beer?  Answer YES to more than three of these items and you just might want to crack open a cold one.


  1. Your daughter informs you that college shouldn't be so bad this semester...  $600 each month isn't bad, is it???
  2. Your neighbor is building a new back porch.  The contractors wake you at 5:30 AM with their power tools.
  3. You walk into the kitchen to make your coffee but fail to realize the dog spilled their entire food dish, efficiently distributing the entire contents across the kitchen floor.
  4. You wake up to find a hole in the back porch's screen and see all the house cats out roaming around in the back yard.
  5. You give more than ten minutes consideration to the possibility of building your own operating system, language, communications protocol, etc...
  6. You firmly think about changing professions; becoming a roadside mowing & snowplow driving person.
  7. You wonder why this month's family prescriptions cost nothing, then realizing you reached your family's out-of-pocket medical insurance maximum of over $10,000 and it's only July.
  8. You don't want to go outside, even if the weather is good, because putting on shoes and a hat requires too much effort.
  9. You leave your art piece on the easel overnight, only to find it perforated by cat claws the next morning.
  10. You find out that your boss is taking the next two weeks off, but then hear from the VP that she has 'just the perfect little project' for you to work on for the next three weeks.
  11. You had to interact with anyone from sales and/or marketing.
  12. You look in the refrigerator and giggle when you see that can of whipped cream you bought for 'happy-fun-time' with your special someone.  Then, you just hang your head and close the door after realizing you bought it three weeks ago and is still not open.
Ya...  Early beer day for me.

Thursday, July 9, 2015

PROPERTY RENTAL SCAM ALERT!!!

Here's how it works...


  • The scammer looks at real estate websites for properties that are for sale.
  • They find a house with plenty of pictures online.  All of the photos and property info is downloaded.
  • Then they search online records and find the name of the current owner.
  • With that information they create a Craigs List (or other on-line service) rental advertisement, posting all the pictures and property information.  All communications with this scammer is through e-mail or a burner cell phone.  (In our case, the scammer was using a Phone/text/SMS anonymizer service.)
  • Requests to view the property by prospective tenants will result in a response like, "I am not available to show it to you, but there are workers there that will let you in."
  • When the tenant feels it is time to move to the next step and put down the deposit, the scammer will e-mail customized lease documents (from a junk Yahoo or GMAIL account).  At this point, the scammer may say there are others interested in the property and that the prospective tenant should hurry the remainder of the process.
  • The prospective tenant will be asked to sign and email the documents back as quickly as possible.
  • Then, the scammer will ask for the deposit and first month's rent up front through a wire transfer or Western Union.


And... **POOF**  The prospective tenant is out about $1000!

All of the above happened to my daughter, except for the last two items...  The lease agreement looked fishy and that is what made us stand back and say 'whoa!'  Fishy how, you ask?  Here's a list...

  1. The lease asked for the deposit and first month's rent by the end of the day, but keys would be exchanged at a later date.
  2. The legalese in the paperwork looked OK, but having signed several leases myself before, there seemed to be many parts missing...  like where to send the monthly payment, contact information for maintenance & service, an arbitration clause, references to other documents not included in the e-mails, etc...
  3. The person's email signature looked like it came from a valid company in Tyler, TX.  I looked up the company and they didn't have an office in Tyler.
  4. The lease agreement had the "landlord's" signature with a Texas notary stamp & notary signature.  BUT!!!  The notary stamp had no notary registration number.

SO, I looked up the previous real estate agent's MLS listing for the property and called her.  Sure enough, she had received several reports of possible rental scams on that specific property.

Then, I called the Texas Secretary of State's office and asked them to confirm the notary's name.  No confirmation - that person was not a notary, and they confirmed there should be a notary registration number in the stamp.

The scammer sent two documents; a welcome letter (.doc) and lease agreement (.pdf)  I scanned them for viruses and after being sure they were clean, opened them up to find a different name...   The DOCdocument was last modified by "Philip Ijem".  The PDF document was authored by "Philip Ijem".

Heck, we are probably lucky the police weren't called or we weren't shot at when we went to look at the property last Tuesday.

All of you looking for something to rent, BE CAREFUL!!!  Check, check & check again!!!

I hope "Philip Ijem" doesn't come face-to-face with my daughter in the next few days...  She is PISSED!!!

Wednesday, July 8, 2015

8 Reasons for a New Operating System

Many years ago you could find me sitting in front of my computer wearing one of my well-worn Linux t-shirts or baseball caps, just programming my brains out, secretly wishing the universe of computers ran on one flavor of Linux or another.  Today, well, I am happy to simply have my Windows 7 machines humming along in front of me for at least a week without pause or crash.  Anyway...  over time I believe Linux has migrated from an OS that performed well & was fairly simple to install and operate, intended to make any computer geek giggle with delight, to something somewhat sloggy and overly complex that now give those same computer geeks headaches and the occasional nightmare.

Anyway, not that I have the technical ability in my current state, I would love to write a new operating system.  Why?  Here are eight reasons:

  1. Performance gains from increased hardware capabilities have been severely strangled by poorly performing code and the belief that the faster hardware will compensate for less than stellar code.  A new operating system should centrally focus on core performance at the expense of general purpose functionality.  
  2. Malware...  Viruses...  Keystroke Loggers... Spyware...  One of the key reasons this crap is proliferating is because we have the same-old operating systems and code and utilities.  A new operating system should have some basic security in mind when designing basic low-level functionality.  And, simply by nature, a new OS would be impervious to these nasties for a while.
  3. Current OSs are COMPLEX!!!  They try to be the do-all, know-all solution to everything.  Someone (or something) that tries to do everything will never do anything specific very well.  A new operating system should focus more on doing computery things, rather than everything under the sun.
  4. Developer environments and tools for Windows and Linux are fragmenting so badly, researching solutions and problems, depending on the situation, can be a near-futile exercise.  A new operating system could provide a new & clean slate.
  5. The windowing OS paradigm is dying.  Yes, I said it.  Don't get me wrong, the windowing paradigm will be around far longer than I.  However, it is my firm belief that virtual reality, tactile and audio human/computer interfacing will be the future.  A new operating system should have a low level text base interface for baseline operations, maintenance and debugging, and perhaps a windowing interface for coding, but should focus at these newer human/computer interfaces.  And, just as a note, all functions capable of being performed by the computer, should be allowed through the text interface.
  6. The Keep It Simple and Stupid concept has been, for the most part, thrown out by most modern operating systems and development tools.  A new operating system should embrace the KISS concept.
  7. Ever notice the slow access to directories with thousands of files?  OK, there may be solutions but it just peeves me off when I have 10,000 or 20,000 files in a directory and handling this many files is so slow (in both Windows and Linux) I can take an afternoon of coffee & smoke breaks.  A new operating system should minimally have the ability to support fast handling of large number of files.
  8. Provide a more rich computer eco-system.  Sometime I think Apple and Windows and Linux devs are getting lazy, just hunting for and polishing the low-hanging fruit.  A new operating system that performs well, has a vibrant development environment will place pressure on existing ecosystems and provide evolutionary pressure.
What are you waiting for???

Tuesday, June 2, 2015

A Little Nostalgia - And What the Hell Happened to Performance?

Right now I am sitting at a computer with 16GB of RAM, 500GB of SSD main storage and a 300GB 7000 RPM hard drive for data, all being controlled by an Intel Core i3-3240 CPU running Windows 7 Ultimate.  Not a blazing gaming machine but I can comfortably work all day and make a decent living.

Well...

As long as no update is processing or it doesn't attempt to digest a bad update or some mysterious internal process isn't sucking up resources like a sump pump in flood season.

Then, using this piece of hardware is not only a large pain in the ass, but sometimes causes days of poking and prodding to back-out an update that went wonky.

First I had the little Timex Sinclair ZX-81.  Great little machine with it's 2.25 MHz Z-80 processor and 32KB Ram.  Yes...  Kilo-Byte.  The OS was burnt onto ROM or EEPROM, so before the TV caught it's video sync, the thing was booted up.

On the down side, there were two computer languages (that I knew about anyway), a crappy version of BASIC and Z-80 assembler (that I never really got to work well).  OK...  This was not a shining piece of computer hardware, nor a fine example of performance...  but it did boot fast!

Then, my third machine...  A Commodore 128 - actually a Commodore C64 and Z-80 driven CP/M machine in one box.  Connect a hard drive and a modem and you could surf the world.  Oh, sure, the web was dominated by ARCHIE and GOPHER and FTP and simple E-Mail, but one could accomplish what one needed; and quickly as well.  I distinctly remember downloading a C compiler for CP/M and writing an IBM-370 assembler on that thing.

Maybe I am getting old, but I would REALLY rather have something that just worked than something glittery and new and expensive that is amazingly fast, so long as the CPU is clicking off NOPs.

Tuesday, May 19, 2015

A Better Weather Channel?

Being a weather geek from the time I saw my first tornado way back in the early 1970's, naturally, the Weather Channel has never been far from wherever I happened to be at any moment.  While in college back in the mid 1980's the Weather Channel was my background study noise.  It was also my pre-spotter alert tool.  Any time they predicted bad weather, I was certain to ensure my car was gassed up and my ham radios charged and ready.

Unfortunately over time, the folks at the Weather Channel have moved away from the "all weather all the time" concept that I dearly loved, to a "weather-tainment" paradigm.  Don't get me wrong; I do not 'hate' this new concept.  I do like watching Prospectors and still don't mind experiencing some of the slicked-up weather tech.  It's all the other programs they have that just irritate me.

The other day my wife introduced me to a new channel on Dish called WeatherNation.   WOW!  No odd programs that only have a tentative relationship to weather.  Definitely a more "all the weather all the time" programming concept.  They may have won a convert here; I like it.

Monday, March 30, 2015

Odd-Sounding Academic Paper Title

YA... ya... ya... It's been a while since least posting. Life can be extremely busy out here.

Anyways, here is something that caught my eye this morning. "Can bloogle resonators enhance representation of time, space and culture through the Person-Environment-Occupation Model" The paper's abstract can be found on Academia.edu

Not sure if this is a spoof or not.  Using those irritatingly enjoyable 'bloogle' noisemakers in an academic paper to possibly enhance the representation of "...time, space and culture..." just seems a bit off to this old geek.

Well, unless there's a time travel theory in there somewhere.  Then that would be COOL!

Sunday, January 18, 2015

Making Glade run on Precise Puppy

Being a Crazy Old Programmer, there are times when Crazy Old Programmer Thoughts create little fires in far-flung reaches of my brain.  About a year ago I started collecting night sky images with the thought I would write a C# program to watch for odd things up in the heavens.

Specifically I wanted to look for meteorite trails and bolides.  It was not a success but not a failure.  The proof-of-concept was to make one second exposures and save 24 hours of these images.  Exposure time on day sky images would be adjusted accordingly.  That would yield about 86400 files for each 24 hour period.

Windows choked horribly.  Copying that many files from one directory to another required more than an hour of the computer's time.  Processing the images were slow, likely due to the file system and that C# doesn't compile to the hardware, rather to an intermediate CLI.

Anyway, I started looking and thought I would experiment with minimal Linux distributions.  First one up is Precise Puppy.  Install on my little HP mini was fairly painless and overall the OS is extremely responsive for such minimal hardware.

Next step is getting the DEVX package installed and running. 

Friday, January 16, 2015

Slow it Down, Son!

I have been trying to tell programmers to 'just slow it down and think a bit' for years.

Whether you’re knitting or programming, working faster will only slow you down. Or at least that’s what Jeffrey Ventrella argues. In “The Case for Slow Programming“, the tech author makes the claim that software developers need to slow down if they want quicker results.

Nice article.  Take a look at it here.

Wednesday, January 14, 2015

Difficult Holidays - Yet Another Lesson on Enjoying the Simple Things in Life

Some lessons in simplicity come as gently as a Sparrow's feather landing on your arm.  Others are more difficult to accept.

We divorced back in 2007.  She liked the complex life, full of intrigue and lies and deceit and conspiracy.   It's not that she was happy with this, she never seemed happy, wanting things to be increasingly more complex.  She would spend days analyzing events and gossip to arrive at conclusions that seemed outrageous to a simple fellow like myself.

Aside from an occasional text, we had no communications, likely for the better as we were certainly not compatible.  She may have begun learning the pleasure that comes with simplicity a little too late.

A few days before Christmas she passed in her sleep, after a day of making cookies with a neighbor.

So, please take some time to enjoy the simplicity in your life.  So often our lives become twisted and complex.  That is not where peace thrives.  Find that peace and enjoy it.