2009年1月16日 星期五

ThreadPool..::.QueueUserWorkItem 方法 (WaitCallback, Object)

參考 MSDN  http://msdn.microsoft.com/zh-tw/library/4yd16hza.aspx

// This example shows how to create an object containing task

// information, and pass that object to a task queued for
// execution by the thread pool.
using System;
using System.Threading;

// TaskInfo holds state information for a task that will be
// executed by a ThreadPool thread.
public class TaskInfo {
// State information for the task. These members
// can be implemented as read-only properties, read/write
// properties with validation, and so on, as required.
public string Boilerplate;
public int Value;

// Public constructor provides an easy way to supply all
// the information needed for the task.
public TaskInfo(string text, int number) {
Boilerplate = text;
Value = number;
}
}

public class Example {
public static void Main() {
// Create an object containing the information needed
// for the task.
TaskInfo ti = new TaskInfo("This report displays the number {0}.", 42);

// Queue the task and data.
if (ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), ti)) {
Console.WriteLine("Main thread does some work, then sleeps.");

// If you comment out the Sleep, the main thread exits before
// the ThreadPool task has a chance to run. ThreadPool uses
// background threads, which do not keep the application
// running. (This is a simple example of a race condition.)
Thread.Sleep(1000);

Console.WriteLine("Main thread exits.");
}
else {
Console.WriteLine("Unable to queue ThreadPool request.");
}
}

// The thread procedure performs the independent task, in this case
// formatting and printing a very simple report.
//
static void ThreadProc(Object stateInfo) {
TaskInfo ti = (TaskInfo) stateInfo;
Console.WriteLine(ti.Boilerplate, ti.Value);
}
}
///////////////////////
當執行此敘述 if (ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), ti
ti會一起傳送到 ThreadProc(Object stateInfo) 裡面的
stateInfo
因此 在
ThreadProc(Object stateInfo)中 需要轉換 Object 為 TaskInfo 型態再轉存一次

2009年1月12日 星期一

淺談多執行緒

參考

C# 隨性筆記


淺談多執行緒(一) --多執行緒介紹:定義,造物件,與啟動

淺談多執行緒(二) --多執行緒共用資料的碰撞問題與LOCK

淺談多執行緒(三) --多執行緒死結deadlock 與使用Monitor.TryEnter方法鎖定

補充:

1.參考MSDN
  • 建立和執行執行緒
  • 執行緒的同步化
  • 執行緒間的互動
  • 使用執行緒集區
  • 使用 Mutex 物件來保護共用的資源
http://msdn.microsoft.com/zh-tw/library/aa288472(VS.71).aspx

2.用於非同步的
ManualResetEvent
http://www.webjx.com/htmldata/2006-08-14/1155517019.html

幾個翻譯網站

zhua niao 抓鳥網(簡) -- web2.0
http://dict.zhuaniao.com/

蝙蝠英語(簡) -- 學習用的沒法英翻中
http://www.binvor.com/

蜂海詞(簡) -- 簡潔啊,還可以serch google, wiki, ...
http://tel.dict.cn/

2009年1月5日 星期一

2008年12月26日 星期五

常用簡體字意思

簡體 繁體

帧 -> 封包 (EX: 以太网帧长度 ->乙太網路封包長度)

数据库->資料庫

素數定理->質數定理

散列表 -> 雜湊表(Hash Table)

析构函数 -> 解構函數

續~

2008年12月14日 星期日

字元分割

JAVASCRIPT提供 split(',') //以逗點做字串分割

ex:
var stringArray = "123,456,789" ;
var getElement = stringArray.split(',')[1] ;

getElement 輸出即為 456 ~~~


PHP 提供 explode() //可以用特定字元切割字串,並存入陣列中

語法: $要被存入的陣列變數 = explode("分隔符號",要被切割的字串);
ex :
$engWords = "abc,def,ghi,jkw" ;
$words = explode(",", $engWords);
echo $words[0]; // abc
echo $words[1]; // def


ref: http://tw.php.net/explode

2008年11月15日 星期六

在BLOG貼程式碼

http://www.opinionatedgeek.com/DotNet/Tools/HTMLEncode/Encode.aspx

進入以後 貼上程式碼 點擊encode

就會自動產生
<
"

再繼續測試上面的話咧

<
"

<
"

...別無聊了

測試 string 於 javascript & php

html 的form 經過 POST 或 GET method 傳過來時,只能用PHP網頁接 ..新發現
題外話~~

重點~~~~~~~~~~~~~~
傳過來是
<input name="phonenumer" type="text" value="phone" >
<input name="checknum" type="text" value="chk" >

這個來接收
accept.php

<?php
$phonenumber = $_POST['phonenumer'] ;
$checknum = $_POST['checknum'] ;
$_SESSION['phonenumber']=$_POST['phonenumer'] ;

echo '$phonenumber='.$phonenumber ; //$phonenumber=phone
echo $phonenumber ; //phone
echo "$checknum" ; //chk

?>
<script type="text/javascript">
//<![CDATA[


alert("ffff") ; //ffff
var phonenumber1 ="4536" ;
//表單傳遞資訊存入javascript
alert("<?php echo 'fssfdsfsdf' ?>") ; //fssfdsfsdf
alert("<?php echo "$phonenumber" ?>") ; //0988...
alert('phonenumber1') ; //phonenumber1
alert("phonenumber12") ; //phonenumber12
alert(phonenumber1) ; //phone

var phonenumber = <?php echo "\"$phonenumber\"" ?> ;
alert(phonenumber) //phone
var phonenumber = "<?php echo $phonenumber ?>" ; //存成 phone 字串
alert(phonenumber + '000') // //phone000
var checknum = "<?php echo "$checknum" ?>" ; // 存成 chk 字串
alert(checknum + '000') //chk000

alert("http://140.1xx.xxx.xxx/ixxxx/mxxxl.php?temp="+"&phonenumber="+ phonenumber) ;

// XMLHttpRequest通訊 ;
// function getLonLat(url){
// var request = GXmlHttp.create();
// var theDate = new Date(); //為了避免瀏覽器快取
// request.open("GET","http://140.1xx.xxx.xxx/ixxxx/mxxxl.php?temp="+"&//phonenumber="+ phonenumberr="+ phonenumber , true) ;
//失敗...

var url="http://140.1xx.xxx.xxx/ixxxx/mxxxl.php?temp="+theDate.getDate()+theDate.getMinutes()+theDate.getSeconds()+"&phonenumber="+ phonenumber ;
alert(url); //http://140.1xx.xxx.xxx/ixxxx/mxxxl.php?temp=165349&phonenumber=phone

2008年11月12日 星期三

xmlHttp


http://blog.roodo.com/jiing/archives/1052181.html

http://www.microsoft.com/taiwan/msdn/columns/ASPNET_2/aspnet_2_20051212.htm


http://newweb.syups.tp.edu.tw/documents/memo/PHP/php_develop.htm


http://audi.tw/AJAX/