Thursday, August 23, 2007

Using AjaxPro2.dll from Michael Schwarz

*Add web Config
inside configuration/configSections

inside configuration/system.web/httpHandlers

*add reference AjaxPro2.dll into the bin folder
using AjaxPro;

* in page load (postback and not) - add Utility.RegisterTypeForAjax(typeof(_Default));

On client ajax method add attribute
[AjaxMethod(HttpSessionStateRequirement.ReadWrite)] public string MyAjaxMethod(string username)
return "Halo" + UserName;

*call in client javascript

Wednesday, August 8, 2007

Thread and Delegate Issue

Run Thread with Parameters
*** But it is only limited to 1 object...

Thread t = new Thread(new ParameterizedThreadStart(Run));
t.Start("an Object");

or using Thread Pool
ThreadPool.QueueUserWorkItem(new WaitCallback(Run), "an Object");

*** Use Class method...
class UrlFetcher
string url

public UrlFetcher (string url)
this.url = url;

public void Fetch()
// use Any Attribute here

UrlFetcher fetcher = new UrlFetcher (myUrl);// Set All the input
new Thread (new ThreadStart (fetcher.Fetch)).Start();
or Call Delegate Asyn

delegate void MyDel(object a, object b);

MyDel d = new MyDel(Fetch);
d.BeginInvoke(a,b,new AsyncCallback(AfterRun),"this is state");



void Force(Delegate method, object[] args)

Sunday, August 5, 2007

Coding Issue

Finalize VS Descructor

Finalize and (~) Desctructor is the same

in VB - use Finalize
in C# - u can not use Finalize - must be desctructor (~)

Protected Overrides Sub Finalize()
' Desctructor code to free unmanaged resources
End Sub

~ ClassName(){}

***Desctructor will be called by the garbage collector - if you call

GC.Collect VS GC.SuppressFinalize(Object)
Collect - will run Garbage Collector - which run your Desctructor / finalize
- However I realize It will run before you create another object.

SuppressFinalize - will not run.. your desctructor on the object

Dispose() Vs Descructor

Desctructor - will guarantee run by Garbage Collector - But It may time Lag even you put GC.Collect(); - it Collect.. after you create another object

Dispose - If you need to explicitly clean up without waiting GC...
- But It will not be run by GC - You need to call

or using using Keyword in CS
Using(Object obj = new Object);

Note you call the Dispose method yourself and in Desctructor there is .Dispose as well...
, you should suppress garbage collection on the object once it's gone, as we'll do here.

*** My preference is use Desctructor... to eliminate the risk - and called GC.Collect();

ROUNDING Decimal 2 Digit
Math.round(123.23123 * 100) / 100
ROUNDING Decimal 3 Digit
Math.round(123.23123 * 1000) / 1000

REF and OUT in C#
Ref to use in and out..
out is for out only... you can not parse put input in it... you need to init inside the method...