2008年7月9日 星期三

關閉 vista superfetch

使用 Windows Vista 時,會發現一開完機,系統就會拼命的使用記憶體,一直到用光為止,這是因為 Superfetch 功能,它會預先載入 (快取) 你之前常用的程式和檔案到記憶體中,以便於加速程式啓動的速度,你可以在以下 Registry 中,找到一個名為 EnablePrefetcher 的機碼值:
代碼:
HKLM\System\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters

EnablePrefetcher 這個值的設定:
代碼:
0=停用
1=Superfetch 應用程式
2=Superfetch 開機程序
3=Superfetch 兩者


你也可以將 Superfetch 這個服務設定成停用,完全不使用 Superfetch 功能。

另外,Vista 的另一項功能 ReadyBoost,可以進一步改善 Superfetch 的效能,它可以讓整個快取流程加速,改由從隨身碟將常用的程式和檔案載入記憶體,而不是從硬碟。

如果要停用 ReadyBoost 功能,可以直接停用 ReadyBoost 這個服務。

2008年7月7日 星期一

防止表單被重複 Submit 送出

方法1.
<body onbeforeunload="oIn=document.getElementsByTagName('INPUT');for(i=0; i<oIn.length; i++){oIn(i).disabled=true};">
PS. 此方法會跟 listview 的 NumericPagerField DataPager 及 BWSLib.DefaultGrid 相衝

方法2.
於網頁上放置ScriptManager,UpdatePanel
將送出按鈕放置於UpdatePanel中
於網頁最後加入下面程式

<script language="javascript">
// Get a reference to the PageRequestManager.
var prm = Sys.WebForms.PageRequestManager.getInstance();

// Using that prm reference, hook _initializeRequest
// and _endRequest, to run our code at the begin and end
// of any async postbacks that occur.
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

// Executed anytime an async postback occurs.
function InitializeRequest(sender, args)
{
// Get a reference to the element that raised the postback,
// and disables it.
$get(args._postBackElement.id).disabled = true;
}

// Executed when the async postback completes.
function EndRequest(sender, args)
{
// Get a reference to the element that raised the postback
// which is completing, and enable it.
$get(sender._postBackSettings.sourceElement.id).disabled = false;
}
</script>

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...