Sep 20, 2007

Threading in C#

C# supports parallel execution of code through multithreading. A thread is an independent execution path, able to run simultaneously with other threads.

To know how its working, when to use thread etc. have a look at 'delicios'

Sep 12, 2007

Display images Directly from Memory

Hello Friends,

I was looking for functionality in which I just need to throw jpg file after changing it into memory.

One way is, save it to hard drive and then use it as target of some img tag. But this is not a good idea, so searched for such kind of logic where I can directly throw the image to client.

I used following code

//Load the bitmap image
System.Drawing.Bitmap objBitMapOriginal = new System.Drawing.Bitmap(strImagePath);
//Change the bitmap image
System.Drawing.Bitmap = ScaleAndModifyImage(objBitMapOriginal);
//Save it to response
Bitmap.Save(Response.OutputStream, ImageFormat.Gif);

But this has some problem as images saved in OutputStream I cant show any other literals or data on the same response.

Then I found a solution, First store the image in session and dynamically sets the src of image which at the end pointing to same page, on requesting that image src it throws the image which is in memory and after finishing work just flush the session.

Its fairly simple, have a look at the delicious. You can also find the code.

Sep 4, 2007

How to expire previous page

Hello all,

This is the normal problem we all are facing in Web application.

Problem comes when user use back button of browser and application start malfunctioning.

Just add following code in page load

Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(0, 0, 2));
Response.Expires = 0;
Response.CacheControl = "no-cache";