IIS是一個線程伺服器,每一個asp都是一個線程,因而跨session,application就必須滿足這一點。遺憾的是,vb是一個面向進階應用程式的開發工具,並不支援跨線程的組件,只能編寫單線程的組件。而猴版的vbs更是如此,在vbs中用class定義出來的對象一樣不允許跨線程。
要突破這一點,就必須使用vc,cb之類低級的開發工具,而其中手工定義介面,IDispatch,IUnknown,UID之類的事,讓人頭昏腦漲,即便是vs.net 2005 , cb6中 ,也似乎沒有多少改善。
下面引用cb的一段協助來說明各種組件的不同
Automation Objects can have one of the following:
Single Only one client thread can be serviced at a time. COM serializes all incoming calls to enforce this. Your code needs no thread support.
Apartment Each object instantiated by a client is accessed by one thread at a time. You must protect against multiple threads accessing global memory, but objects can safely access their own instance data (object properties and members).
Free Each object instance may be called by multiple threads simultaneously. You must protect instance data as well as global memory.
Both This is the same as the Free-threaded model, except that all callbacks supplied by clients are guaranteed to execute in the same thread. This means you do not need protect values supplied as parameters to callback functions.
Neutral Multiple clients can call the object on different threads at the same time, but COM ensures that no two calls conflict. You must guard against thread conflicts involving global data and any instance data that is accessed by more than one method. This model should not be used with objects that have a user interface. This model is only available under COM+. Under COM, it is mapped to the Apartment model.
希也不要太深究此問題,C程式員和asp程式員的薪水差別之大是顯而易見的,我想當真能夠用c編寫出需要的組件時,沒人捨得回到廉價的asp工程上了。