Author Archive

Creating threads that can interact with form elements, an easy alternative

I’ve been working on a personal project (more for learning than anything else) in C# where the user can perform a search and preview images as thumbnails on a button then select an image they want. I wanted images to start showing up as soon as the user began typing. The time it takes to shrink just 9 full sized photos to a thumbnail image is large enough that performing the search can become unbearable. Naturally I decided to solve the problem using threads, but ran into a brick wall when an exception was thrown – apparently, developers are unable to change form elements from different threads.

The exception had a link I followed that gave information on how to overcome this issue. While the article was not super easy to follow, I was able to manage. I noticed a lot of people posted questions on forums on how to overcome this error, so I got to thinking and came up with what I think is an easier alternative.

My basic setup is as follows:

  1. The buttons are first created on the form.
  2. A timer is started.
  3. Threads are created that shrink images to thumbnail sizes for being displayed on the button.
  4. A class ThreadedQ is created in which it stores a thread number, a reference to a button, a reference to the image to be shrinked, and a reference to Q (defined next)
  5. The calling form has a variable, List Q, defined.
  6. As threads complete, they push ThreadedQ objects onto Q.
  7. Whenever the timer ticks, it checks Q for items; when one is found, it maps the newly created thumbnail to the button it references.
  8. When all threads have completed, the timer stops.

While this setup may not be as good as what the original tutorial proposed, I think it may be easier for beginners to follow.

Leave a Comment

GridMove

Ever have a lot of windows open at one time? Ever want to lay them all out nicely without having to do a lot of manual dragging and resizing? Then you should take a look at a small utility called GridMove.

On my system, I can press Windows+G at any time and resize and place the current window in the top left corner, or fill the entire right half the screen (or a number of other configurations), or force it to be on top of all other windows by pressing 1-9. You can choose from a number of “templates” (mappings of buttons to screen locations) or create your own.

I find this utility to be helpful when programming (cycling through tutorials, code, output, etc) and grading programs for my TA position, where I have literally seven active windows up at a time.

Gridmove can be found here: http://jgpaiva.dcmembers.com/gridmove.html

Comments (1)

Windows Grep

A recent project I’ve been working on was built with Ruby on Rails. Anyone who has had the experience of starting to learn RoR by working on another person’s already built project may agree with me – finding how things are generated is difficult. When I wanted to change text or learn where the design was stored, I had a rough time. Then I discovered Windows Grep.

Windows Grep allows users to do in depth file searches. The user can define a string to search (or a regular expression) and specify a directory and file types and the program searches within the file’s contents.

In case you were not aware, Grep comes from a unix command and is an ancronym for Global Regular Expression Print. There are variations of this tool for windows, but I am drawn to Windows Grep because of its GUI layout and informative search results.

I used this tool by looking at a web page on rails, viewing it’s source, copying a small string of text that I thought would be unique, and pasting it into Windows Grep to find results. It certainly helped with the beginning stages of learning my way around the project.

Windows Grep can be found here: http://www.wingrep.com/

Leave a Comment

ZedGraph – Making My Life Easier Since Friday

Given the task to create a dashboard for a client, I went through the usual steps of building a project – the initial frustration of finding a library to handle the more intricate portions of the project, figuring how everything will be laid out, etc. Luckily, I stumbled across an amazing library for handling graph generation in C# called ZedGraph.

You can find the source code here:
http://sourceforge.net/projects/zedgraph/

A wiki is also available:
http://zedgraph.org

And a handy startup tutorial:
http://www.codeproject.com/csharp/zedgraph.asp

Leave a Comment