Blocking unwanted advertisements and malware with a HOSTS file
0 Comments Published January 18th, 2011 in Uncategorized, MVP ProgramA fellow Microsoft MVP has assembled a large list (> 6MB) of domain names/IP addresses mainly used to serve advertisements, tracking cookies, and sometimes even malware.
You can find the full instructions at http://www.mvps.org/winhelp2002/hosts.htm. I personally have been using this list for almost two years now (it is frequently updated).
Because I have IIS set-up on my main machine I decided to change the redirect IP address to 0.0.0.0 instead of 127.0.0.1, so that IIS is not “bothered” with the failed requests.
P.S. This list also blocks the YouTube commercials, which is a nice touch!
Multithreading with Windows Forms in C#
0 Comments Published December 29th, 2010 in Microsoft, ProgrammingWhat are threads?
A thread executes code synchronously—a set of instructions processed by the CPU “first in first out”. This can include virtually any kind of code, be it updating of the GUI, processing calculations, or waiting for user input.
Windows Forms is arguably one of the most used aspects of .NET Framework. GUI programs typically rely on two layers:
- Processing stack, which includes any code or task executed in the background, and
- User interface, which is supposed to give the user a means for instructing the program to execute tasks, and receiving timely “updates” or indications of progress.
Multithreading
Multithreading is a programming paradigm, which has become popular during the past decade. In a nutshell, the CPU can switch between two or more thread contexts so two tasks (e.g. calculation, and GUI update) can be executed in parallel—or asynchronously.
For example, a program can make full use of a multi-core processor by instructing each core to process a separate task, or a chunk of the whole task. This results in improved performance.
In the case with Windows Forms, a separate thread can be used to process a task while allowing the main thread (GUI) to provide timely information about the progress, or to let the user continue their work during the lengthy task.
Честита Коледа (и поздравления на спечелилите)!
0 Comments Published December 26th, 2010 in MVP ProgramЧестита Коледа, и приятно посрещане на Новата година на всички читатели на блога!
Също така поздравления на Miguel Hernandez (@migue333) и Kim Nilsson (@no_substitute), които бяха избрани посредством случаен жребий от Bryant Zadegan и мен, за да получат по един подарък-карта за абонамент MSDN Ultimate.
Честито!Благодарности на Microsoft за подкрепата.
A simple backup solution using ImageX, a Windows Imaging tool
1 Comment Published September 18th, 2010 in Microsoft, ProgrammingPrevious readers of my blog might already know that I am a big fan of ImageX, a tool that has been supplied by Microsoft in the Windows Automated Installation Kit since the release of Windows Vista.
A quick introduction
ImageX is a command-line tool that enables original equipment manufacturers (OEMs) and corporations to capture, to modify, and to apply file-based disk images (.wim files) for rapid deployment.
WIM files can capture disk or directory snapshots in such a that identical files are only stored once in the internal structure of the image. In addition to this, compression can be used to minimize the size of the final data.
These are some of the reasons I have been using ImageX to take full “snapshots” of all of my code, private files, etc. from time to time, for backup and archiving purposes. When needed, I can extract different revisions of the same file, or restore a whole image/snapshot in case of disk damage or data loss.
The graph on the left visualizes the changes to my projects backup file spread across 16 months. The last image’s actual data weighs at 64GB, while the whole WIM is 59GB—and it contains all file changes, directory structures, even information that has long been deleted from my working copy.
Requirements
- The scripts package. Download and extract to a folder of your choice.
- ImageX.
- Download and install the Windows Automated Installation Kit (WAIK).
- Copy the ImageX binaries (both amd64 and x86 folders), located in \Program files\Windows AIK\Tools\ to the backup\app\imagex folder.
Continue reading ‘A simple backup solution using ImageX, a Windows Imaging tool’
Just wanted to post a quick update:
Thanks to the MVP Program I have received two MSDN Ultimate Subscription gift cards, worth $11,899 each.
These are going to be given away soon as I am working with Bryant on the giveaway details. Stay tuned.
FlacReader + WavWriter
As a follow-up to my previous article on FLAC and encoding uncompressed audio, I have further developed the Wav2Flac library and added FLAC decoding to the WAVE container. Some key points of this aspect of the WavFlacTest library are:
- Support for 16- and 24-bit audio streams
- Support for virtually all FLAC channel mappings: mono, stereo, 5.1, 7.1, etc.
- The resulting file is a bit-for-bit copy of the original audio stream
All source code and the compiled 32-bit FLAC library can be downloaded from here.
Known limitations
- Due to the wave format used being 32-bit, uncompressed files greater than 2GB in size might not play in full in some players.
- Even though FlacReader can receive metadata callbacks, the data is not interpreted. This can be further developed using the FLAC API documentation.
One thing that popped in my mind yesterday after having a conversation over twitter (admittedly, a service I had rarely used until recently), is that the more followers you have, the higher the odds you would have to use other languages in addition to a lingua franca. This ‘leaves out’ other friends who could have limited knowledge of foreign languages.
This is how the idea for the Tweet Balloon Translator was born. It’s a Greasemonkey script for Firefox, which uses the balloon/hover feature recently introduced in twitter plus the Google Translate service to translate tweets quickly and inline.
You can install the script from userscripts.org or the local copy here.
Development notes
The key phases I outlined for the script were as follows:
- Establish a working translation block of code using the Google Translate JSON API
- Research the possibilities of inserting a Translate link in such aspects of twitter as the profile page, direct messages, retweets. The Guest/logged out user scenario also had to be taken into account as twitter serves the pages in a different manner.
- Figure out a way to use the twitter internal API for the HoverCard balloon feature. This was probably the hardest of all three because of the way these are created and populated.
- Integrate 1 through 3 in a single script.
Needless to say, the script employs asynchronous requests to Google via the HTTPXMLRequest model so as to not break the UI thread, as well as exception handling.
Please feel free to try out, review, or contribute to the script at userscripts.org. I feel both international and English-speaking users could benefit from this by being able to communicate with more people on twitter, and understand international tweets.
Resizing a form while keeping aspect ratio is useful in many cases, like video playback or vector graphics. This way, the window can be resized while retaining the original ratio and avoiding the use of letterboxing or pillarboxing.
What’s needed is for the window function to be overriden (WndProc) and pre-process the target window rectangle used by the WM_SIZING message.
The new destination rectangle is calculated by taking into account the resizing handle and the window chrome size (title height, border width, etc.).
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SIZING)
{
RECT rc = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
int w = rc.Right - rc.Left - chromeWidth;
int h = rc.Bottom - rc.Top - chromeHeight;
switch (m.WParam.ToInt32()) // Resize handle
{
// …
}
Marshal.StructureToPtr(rc, m.LParam, true);
}
base.WndProc(ref m);
}
You can find the full C# source code here, including a test program. The aspect ratio and initial client size is set to 16:9.
Why lossless?
Lossless audio is used on various media, including studio masters, CD, DVD-Audio (via MLP) and Blu-ray (via Dolby TrueHD, which is technically a rebrand of and an extension to MLP, and DTS-HD Master Audio). All of these, when decoded, will result in a pulse-code modulated signal identical to the source, unlike the popular MP3 format. MP3 performs a quality-file size trade-off by discarding or reducing frequencies less audible to human hearing.
PCM by design uses a constant bitrate, which is proportional to the sample rate, bit depth and number of audio channels, which results in very large file sizes with the increasing of each parameter, and/or duration of the audio track.
Solutions such as FLAC, TrueHD and DTS-HD MA are used to losslessly compress the source audio so that the rest of the medium (for example, a Blu-ray disc) can be used for more audio tracks, higher-bandwidth video or extras.
Out of the aforementioned, only FLAC is free to use—both TrueHD and DTS-HD MA encoders and decoders have to be licensed.
The first part of the series will explore the processing of uncompressed audio data with the FLAC API in C#. In case you prefer to use Visual Basic .NET, you can use this online converter.
Continue reading ‘Encoding uncompressed audio with FLAC in C#’
Command-line interface tools. We usually prefer to write these when we need a lightweight application to get work done.
Some operations can be lengthy, or we simply want to present the a visual indicator of progress to the user. For this purpose I usually update Console.Title for simplicity’s sake.
However, if the tool is intended for a more wide audience (IT professionals or advanced users) you would want a CLI progress bar.
ConsoleProgress is a static class. Usage is pretty much straight-forward:
- Call Reset to reset the progress bar’s state. This is optional if you wish to use the progress bar only once in your program.
- Call Update. You can pass a float to indicate progress using a fraction (0.25 = 25%), or the current and maximum values (e.g. 17 of 100 items processed).
- If the operation can be canceled, either because of an internal exception or by the user, you can set the Canceled property to true to update the console output.
The sample code also contains several test cases, which demonstrate successful and canceled operations. I have also used relevant colors depending on each result.
Search
About |

Stanimir Stoyanov is a programmer, Microsoft MVP, and Windows enthusiast. Read More...
He's currently working on an array of projects using Visual Studio 2010 on Windows 7.
Latest
- Blocking unwanted advertisements and malware with a HOSTS file
- Multithreading with Windows Forms in C#
- Честита Коледа (и поздравления на спечелилите)!
- A simple backup solution using ImageX, a Windows Imaging tool
- Soon: MSDN Ultimate Subscriptions Giveaway
- Decoding FLAC audio files in C#
- Inline Tweet Translator
- Resizing forms while keeping aspect ratio
- Encoding uncompressed audio with FLAC in C#
- Indicating progress in console windows
Also visit
Friends
- Andre Da Costa is Teching It Easy
- Christoffer Andrersson Executive Consultant at TrueSec
- Olcay Buyan Software developer and Media Center enthusiast
- Rafael Rivera Within Windows
- Steven Troughton-Smith iPhone Developer (Doom, Lights Off) and hacker extraordinaire
- Zack Whittaker iGeneration at ZDNet.com
