·一个简单的CustomItem使用案例
·CustomizeGoogle:让Firefox搜索更上
·用CustomDataSource向iReport中传递数
·User Tips: Using Return Values from
·Custom Channel Sinks被我征服了
·Cisco Unified Customer Voice Portal
·使用CustomValidator模仿show出一个co
·Efficient service of Microsoft‘s C
·Creating Custom Web Controls in C#
Custom Thread Pooling Template
Now that we have covered the basics of Visual Studio .NET project types and templates, let us look at how we can write our own custom project template that will generate a thread pool that can be used by the developer without any modifications at all. Before we start discussing the custom template, let us focus on writing a thread pool class that will be a part of this template.
A thread pool usually consists of two classes: one class that represents a thread, and another class that represents the object that manages a pool of these thread objects. The thread class is fairly simple: it is simply an encapsulation of the built in System.Threading.Thread class, but the thread pool class is slightly more involved. This thread pool class has to create all the threads in the pool, assign them work, and keep track of idle threads so that further work can be assigned to them. Further, the threads in a thread pool are created once, and if a thread is idle, the thread goes into an efficient wait mode (like a sleep call). When there is work to be processed, the thread pool is responsible for bringing an idle thread back into active mode and assigning it work.
Let us start by discussing the thread class first.
public class ThreadPoolThread
{
public ThreadPoolThread
(ThreadPool iThreadPool, ThreadPool.DoWork iWorkerMethod)
{
mWorkerMethod += iWorkerMethod;
mThreadPool = iThreadPool;
mThread = new Thread (new ThreadStart (ThreadFunc));
mEvent = new AutoResetEvent (false);
mThread.Start ();
}
public void ProcessRequest ()
{
mEvent.Set ();
}
public void Stop ()
{
if (mThread != null)
mThread.Abort ();
}
private void ThreadFunc ()
{
WaitHandle[] lWaitHandle = new WaitHandle[1];
lWaitHandle[0] = mEvent;
while (true){
AutoResetEvent.WaitAll (lWaitHandle);
mWorkerMethod ();
mThreadPool.ReturnToPool (this);
}
}
private ThreadPool.DoWork mWorkerMethod;
private Thread mThread;
private AutoResetEvent mEvent;
private ThreadPool mThreadPool;
}
This class has four methods, a constructor that sets up the objects required by the class, a method to wake up the thread, a method to kill the thread, and the worker method where the thread will spend its entire life. The ThreadPoolThread object consists of one Thread object and one AutoResetEvent object, which is used to signal an idle thread. The constructor takes in a reference to the thread pool that this thread belongs to, and it also takes in a delegate which is the user defined method that this thread will invoke as part of its processing. The user of this class will pass this delegate, and it typically will be a method that will accept a request (from a socket or from a web service, etc) and process it. Once this delegate method returns, the thread will go into an efficient wait, blocking the event object. This is an efficient wait state that consumes minimal resources. The thread can be brought out of this wait state by the thread pool, by calling its ProcessRequest method. This method simply calls the Set method of the event object, which causes the event object to go into a signaled state. This causes the AutoResetEvent.WaitAll method to come out of a blocking state, and invoke the delegate method. This continues in an infinite loop, until the thread is terminated by the thread pool calling the Stop method.
Let us now look at the thread pool class. Note that this is a custom implementation of the thread pool, which is different from the System.Threading.ThreadPool class. We will start off by discussing the Start and the Stop methods.
public delegate void DoWork ();
public ThreadPool (int iNumThreads)
{
mNumThreads = iNumThreads;
}
public void Start (DoWork iWorkerMethod)
{
mFreeList = new ThreadPoolThread [mNumThreads];
mThreads = new ThreadPoolThread [mNumThreads];
mFreeThreads = mNumThreads;
ThreadPoolThread lThread;
for (int i = 0; i < mNumThreads; i++){
lThread = new ThreadPoolThread (this, iWorkerMethod);
mFreeList[i] = mThreads[i] = lThread;
}
}
public void Stop ()
{
for (int i = 0; i < mNumThreads; i++)
mThreads[i].Stop ();
}
private int mNumThreads;
private ThreadPoolThread[] mFreeList;
private ThreadPoolThread[] mThreads;
private int mFreeThreads;
The first thing that the ThreadPool class defines is a delegate that is used by the thread class to call the method that will perform the actual processing, as explained above. The constructor of the thread pool takes in a single parameter which specifies the number of threads that will be created in this pool. The thread pool is started by calling the Start method, which creates a pool of ThreadPoolThread objects, and stores a pointer reference to these objects in the mThreads and mFreeList arrays (we use arrays for simplicity in this sample: a more efficient alternative would be the use of lists). The mThreads array represents all the threads in this pool, and the mFreeList array represents all the threads that are currently free to service requests. All threads start off belonging to the free list. The Stop method simply calls the Stop method on the ThreadPoolThread class that aborts the thread.
Let us now look at the ProcessRequest method that is called by the client when it needs a thread to process a request. Calling this method causes the delegate that was passed to the Start method to be called.
public bool ProcessRequest ()
{
ThreadPoolThread lThread = null;
if (mFreeThreads == 0)
return false;
lock(this)
{
mFreeThreads--;
for (int i = 0; i < mNumThreads; i++)
if (mFreeList[i] != null){
lThread = mFreeList[i];
mFreeList[i] = null;
break;
}
}
lThread.ProcessRequest ();
return true;
·一个简单的CustomItem使用案例
·CustomizeGoogle:让Firefox搜索更上
·用CustomDataSource向iReport中传递数
·User Tips: Using Return Values from
·Custom Channel Sinks被我征服了
·Cisco Unified Customer Voice Portal
·使用CustomValidator模仿show出一个co
·Custom Thread Pooling Template
·Creating Custom Web Controls in C#
前天发现自己2000系统升级不了,提了个question到微软的Support,结果效率还真不差。 贴上解决方案。提问时我就写了个can not update. 看看他们解决流程:接到提问->转到support->给出solution.
Problem title: | | can not update. |
Product: | | Microsoft Windows Update (All Languages) |
Sent on: | | 3/20/2006 11:47:36 AM |
Last modified: | | 3/22/2006 11:56:54 AM |
|
Description: | | Problem Description: can not update. Operating System:Windows2000 |
|
Your Response - 3/22/2006 11:56:53 AM Problem Description: it's ok now,thanks for effective help. | Response from Microsoft - 3/21/2006 9:58:19 PM Dear Terry,
Thank you for choosing Online Support for your Microsoft Technical Support offering. My name is Harry and I will be assisting you with this service request. For your reference, the Case ID of this service request is SRZ060320000480.
As you mentioned, when attempting to update Windows from the Windows Update site, you encountered a problem that it fails to update. If I have misunderstood your concern, please let me know.
I fully understand the inconvenience you are experiencing. Please be assured that I will try my best to help you resolve the problem.
From the case attachment, I have found that Windows Update fails with the error code 0x80072EE2. Based on my experience, the issue may be caused by several factors. Troubleshooting can be time consuming, but please be assured that I will continue to assist you until the issue is resolved.
At this time, let’s try the following steps to troubleshoot the problem. After finishing each suggestion, please go to the Windows Update site <http://windowsupdate.microsoft.com> and check the result there.
Suggestion 1: Delete the Hosts file ========================= The “Hosts” file is responsible for the local host name resolution. If this file is improperly modified, updates for Windows won’t be successfully installed on the local machine and the error code 0x80072EE2 will be generated. In this situation, to get the problem resolved, we can erase the current Hosts file and the system will spontaneously create a fresh one. Refer to the following steps.
Step 1: Clear the Hosts file --------------------------- 1. Click Start->Run, type %SystemRoot%\system32\drivers\etc and press Enter. 2. Right-click on the file “Hosts” (without quotations) and choose Delete. 3. Click Yes to confirm the deletion.
Step 2: Clean up the Domain Name Resolution (DNS) cache: --------------------------- 1. Click Start->Run, type: cmd and press Enter. 2. In the window, type: ipconfig /flushdns and press Enter.
Suggestion 2: Check the background programs ========================= This behavior can be also caused by security programs such as a firewall or other Internet related applications running in the background, which interferes with the Windows updating process. At this time, please check if any of the following programs is currently installed on the computer that has the issue:
Download Accelerator GetRight Browser Blaster Pop-up blocker
BitTorrent eMute
Sygate Personal Firewall Norton Internet Security Freedom Firewall Zone Alarm Firewall
If they are, please try to find an option pertaining to "Generic Host for Win32" and then disable it. If an option of this sort cannot be pinpointed, I recommend turning off or even uninstalling the whole program and checking the status.
Suggestion 3: Re-configure ISA server or proxy server ================== This error can also occur due to proxy server settings. Please refer to the following Knowledge Base article if a server is being used.
You experience problems when you access the Windows Update Version 5 or Version 6 Web site through a server that is running ISA Server <http://support.microsoft.com/?id=885819>
If you do not have permission to re-configure the settings, please contact your network administrator. If no server is being used, we can refer to the following suggestions.
Suggestion 4: Check proxy settings ============================== Note: If any proxy is necessary to the Internet connection, please contact your ISP (Internet Service Provider) before using the following method to remove the configuration.
1. Open Internet Explorer. On the Tools menu, click Internet Options. 2. Click the Connections tab, click LAN Settings and clear all the check boxes. 3.Click OK. 4. Quit Internet Explorer. 5. Click Start, click Run, type cmd, and then click OK. 6. Type the following commands. Press ENTER after each command.
proxycfg -d net stop wuauserv net start wuauserv
7. Restart the computer.
For detailed information, we can refer to this Microsoft Knowledge Base article:
You receive an "Error 0x80072EE2" or "Error 0x80072EFD" error message when you try to use Windows Update http://support.microsoft.com/?kbid=836941
However, if the behavior persists, I’d like to check the following points on your side:
1. Is the computer currently residing in a company network (LAN) or domain environment? 2. Is the computer connected to the Internet via another computer, router or proxy?
In addition, in order to perform further research, please gather the following information for me.
System Information =============== a. Press Start, Run and type in msinfo32. Press OK. b. Choose Save from the File menu and save it as an NFO file. c. Find the file, right-click on this file, click "Send To", and click "Compressed (zipped) Folder".
Windows Update Log =============== 1. Click Start->Run, type: %windir% and press Enter. 2. Locate a file named “WindowsUpdate.log”. Please be aware that there may be another file named "Windows Update.log". I am requesting the file without a space in the middle of the name.
Please send the above two files to me at v-30hzha@mssupport.microsoft.com <mailto:v-30hzha@mssupport.microsoft.com>. Once I obtain the information, I will perform further research and get back to you as soon as possible. Thank you for your time and cooperation.
Please let me know the results at your earliest convenience. I appreciate your time and effort on this issue. If anything is unclear, please do not hesitate to let me know and I will be glad to help.
I look forward to hearing from you.
Best Regards,
Harry Zhang
v-30hzha@mssupport.microsoft.com <mailto:v-30hzha@mssupport.microsoft.com> Microsoft Windows Support Professional
Satisfied customers are my top priority. Please let either myself or my manager know what you think of the level of service provided. know what you think of the level of service provided. You can send feedback to my manager Joe Shi at v-30josh@mssupport.microsoft.com <mailto:v-30josh@mssupport.microsoft.com>. | Response from Microsoft - 3/21/2006 1:22:21 AM Hello Terry,
I understand you are experiencing difficulties using Wndows Update site.
Microsoft provides no-charge technical support for issues related to Windows Update, so I have forwarded your case to a Support Professional from whom you will hear within 24 hours.
Please note that since this will be handled by e-mail, you may need to adjust any bulk or junk mail filters to allow e-mail from the Microsoft.com domain to ensure you receive your Support Professional's response. If you do not receive a response within 24 hours, please check your junk or bulk mail folder for a message containing your Case ID number, SRZ060320000480, in the subject line.
If, while awaiting your Support Professional's reply, you have any additional questions or information regarding this issue, please add the details to the case notes. You may do so by writing to compmail@microsoft.com with your case number SRZ060320000480, in the subject line of your message.
Thank you for using Microsoft products and services.
Kiran Microsoft Online Customer Service Representative.
If you have any feedback about your Online Customer Service experience please email my manager, Gopala Pradeep, at managers@microsoft.com. | Your Request - 3/20/2006 11:47:36 AM Problem Description: can not update. Operating System:Windows2000 | | |