Sunday, January 15, 2012

Print to Kindle

It is an odd announcement that causes me to hijack my daughters Kindle Fire and Laptop. But I really wanted a sense of how this felt. After downloading the Send to Kindle desktop application onto the laptop and configuring it to use her Amazon account a print option 'Send to Kindle" appears in most applications. The most interesting place is in Word.

In many ways this functions in a manner similar to 'Save as PDF'. The format of what is printed is converted to a format that Kindle can display. The next step is the file is forwarded to Amazons cloud and then forwarded on to the kindle. But this all happens without the user comprehending or needing to comprehending how it occurs.

The result is the document appears on her Kindle. Which means she is now in a position to develop content for the Kindle with minimal effort. Furthermore, this will expand. The end goal is her Kindle becomes the most import device. And it has taken on the role of presenter of her cloud based Amazon account which starts to position itself as the ITunes of information stores.

Friday, January 13, 2012

Winform Background Thread


The easiest way to implement a background worker thread for a form in a Winform application is to use the BackgroundWorker from the System.ComponentModel namespace.




To summarize the changes imagine you have a form were you dropped a button with the default name 'button1'.


  1. From the toolbox open the component section.

     
  2. Select BackgroundWorker and drag it onto the form.
    1. The default name will be 'backgroundWorker1'.
       
  3. Select the backgroundWorker object and inspect its properties.
    1. Select the Events (it looks like a lightning bolt)
    2. Doubleclick in the space next to 'DoWork'
      1. Keep default name: backgroundWorker1_DoWork
    3. Doubleclick in the space next to 'ProgressChanged'
      1. Keep default name: backgroundWorker1_ProgressChanged
    4. Doubleclick in the space next to 'RunWorkerCompleted'
      1. backgroundWorker1_RunWorkerCompleted

         
  4. Button Click Code Handler
     
    private void button1_Click(object sender, EventArgs e)
    {
    this.backgroundWorker1.RunWorkerAsync("From Form");
    button1.Enabled = false;
    }
     
  5. Background DoWork Handler
     
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
    Thread.Sleep(1000);
    string comment = (string) e.Argument;
    backgroundWorker1.ReportProgress(12, comment + " From Background");
    Thread.Sleep(10000);
    }

     
  6. ProgressChanged Handler


    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
    string report = (string)e.UserState;
    listBox1.Items.Add("From Progress Change Hander");
    listBox1.Items.Add(report);
    }
     
  7. RunWorkerCompleted Handler

     
    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
    button1.Enabled = true;
    }

     




Implementation Versions: This code was developed and tested with Visual Studio 2010, C# 4.0 and the .Net Framework 4 Client Profile.