Archive for February, 2008

Dilaogs with timed self destruct

My colleague came to me today with the following question: “How can I inform the user using a MessageBox in a separate thread while the main thread continues working ?”

Since I did not found a direct answer hidden in some corner in my brain, we took a dive in internet together, found some golden fish, and cooked the following recipe:

First we create a minimalistic Form with the needed functionality for timed self destruct :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;

namespace hacks.wordpress.com
{
    public class TimedDialog : System.Windows.Forms.Form
    {
        public TimedDialog()
        {
            this.InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "I am a mission impossible message";
        }

        public void ShowTimedDialog(int time)
        {
            //{{ Setup and start the timer
            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
            timer.Interval = time;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Enabled = true;
            //}}

            base.ShowDialog();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

Now we use the new created dialog in our main application

public class MainApplication
{
    public static void Main(string[] args)
    {
       Console.WriteLine("1");
       Thread mainThread = new Thread(new ThreadStart(MainApplication.startTimedDialog));
       mainThread.Start();
       Console.WriteLine("2");
       Console.WriteLine("3");

    }
    private static startTimedDialog()
    {
        TimedDialog timedDialog = new TimedDialog();
        timedDialog.ShowTimedDialog(5000);
    }
}
Advertisements

Leave a Comment

Notepad++ Demo : Regular Expressions

I have started today a series of demos to show waht Notepad++ hides under the hood. My first demo is an image slideshow that demonstrates the usage of regular expressions.

Slideshow on Picassa

Leave a Comment

Use any font for LaTeX..

LaTeX is a fantastic publishing system. I use it as often as I can. However, when you use it for a long time, the few beautiful fonts available with a standard installation are getting boring. I tried in the past hacks like converting TTF fonts into a LaTeX understandable format, but I was not really successful at that.

Well, today I discovered XeTeX: A LaTeX compiler that generates pdf documents with support to any font installed on windows machine :-)! I checked that and it was as simple as promissed:

  • download and install MikTeX 2.7
  • download the example I created
  • run run.cmd
  • enjoy 🙂

Leave a Comment

The most useful short keys for VisualStudio C#

This list is sticked right on my monitor. It contains the most useful short keys I really use frequently to increase productivity in VisualStudio C#

Code Generation  
Ctrl + R + E generates getters and setters for a property
Shift + Alt + F10 adds a using statement
Code Navigation  
Ctrl + M + M toggles any tag :method, region, class etc. 🙂 (my favourite)
Shift + F12 finds all references to a avariable
F12 goes to variable definition
Text Editing  
Ctrl + L cuts a line

Those short keys are in available in my newly created the reference card : MS Visual Studio C# Reference Card

Comments (1)

LockImage project added to google code

Finally I got my open source project LockImage started on google code. Read more and download it form LockImage

Leave a Comment