Convert a string or an integer to enum type

Something that I always use whenever I use enumeration :

public enum StatusType
		Approved = 1,
		Pending = 2,
		Cancelled = 3

Convert a string to enum :

string currentStatus = "Approved";
StatusType status = (StatusType) Enum.Parse(typeof(StatusType), currentStatus);

Convert an int to enum :

int currentStatusId = 1;
StatusType type = (StatusType) Enum.ToObject(typeof(StatusType), currentStatusId); 

Just be careful with enum conversion, especially when you want to use Enum.IsDefined method as it is very expensive.

Asynchronous processing in ASP.Net using delegate

There are times when we need to get the control of the UI after telling the server to do something, i.e. Bulk upload.  The example below uses delegate to return the control after extracting a large file:

public delegate string ExtractFile(Stream fs);

public void Run(Stream fs)
ExtractFile ef = new ExtractFile(ProcessFile);
ef.BeginInvoke(fs, new AsyncCallback(ProcessFileEnd), ef);
private string ProcessFile(Stream fileStream)
string message = DoSomething();

return message;

void ProcessFileEnd(IAsyncResult result)
ExtractFile ret = result.AsyncState as ExtractFile;

string message = ret.EndInvoke(result);

Notice that I use AsyncCallback when calling the beginInvoke. This can be used if we want to do something after the long task. However I haven’t found a good way to update the UI in ASP.Net -_-