Thursday, February 24, 2005

Cryptanalysis of SHA-1

Read Cryptanalysis of SHA-1 by Bruce Schneier.

Friday, February 11, 2005

WaitForSingleObject(Handle, Timeout)

Recently I was working on a problem where I had to create new process on a click of a button. With this, I needed some callback or signal when this new process terminates. This new process was launched on a new thread. I looked into the Thread Class but there was no out of box functionality to achieve this. So I end up writing this code.

Here is the PInvoke Declaration

[DllImport("Kernel32.dll", CharSet=CharSet.Unicode,SetLastError=true)]
static extern uint WaitForSingleObject(
uint Timeout);

Creating a new Thread to start our process…

newThread = new Thread(new ThreadStart(StartNewApplication));
newThread.Name = "ClientApplication";

private void StartNewApplication()
const uint INFINITE = 0xFFFFFFFF;
uint returnValue;
int error;

//Creating a new process
Process pr = new Process();
pr.StartInfo.WindowStyle = ProcessWindowStyle.Normal;

//Using WaitForSingleObject to wait till the threads give a
//signal. As we want to get signaled when the thread gets
//terminated, we set timeout time as "Infinite".
IntPtr HANDLE = pr.Handle;
returnValue = WaitForSingleObject(HANDLE,INFINITE);
if (returnValue == 0xFFFFFFFF)
//Getting error code...
error = Marshal.GetLastWin32Error();
//Code which we want to execute after the thread has been terminated