junwei's profileRichard's footprint on ....PhotosBlogListsMore ![]() | Help |
|
Richard's footprint on .NETMay 30 System.Threading.TimerIn one of our system, there is a task which demands to check the incoming mail task periodically and send it out if any. Since it is a sole task, no need to much communicated heavily between threads, just scan the database mail table to pull out these task and send. Compared the currently existing three different APIs in .NET, one is mainly for windows form application, one is for accurate and complex server multiplethread application, and the third one is the lightweight timer for simple thread task, it is System.Threading.Timer. I chose the last one as my solution. Here I put the presudo codes for further reference.
System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(WorkerClass.ExecuteMailTask));
timer.Change(1000,0); // specify start timer after 1 second
...
in my WorkerClass, I define one static method ExecuteMailTask to stop timer temporarily and execute the mail task. the following is the preseudo codes
ExecuteMailTask(object state)
{
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +"mail monitor task is running on thread #"+Thread.CurrentThread.ManagedThreadId);
System.Threading.Timer t = (System.Threading.Timer)state; t.Change(Timeout.Infinite, Timeout.Infinite);// first stop the timer teporarily
... // necessary codes to pull out mail data
t.Change(0,20000); //restart the timer
}
I have omitted the exeption handling codes, in a product enviroment, wrap above codes in a try ...catch.. finally block will be an apropriate choice when robustness is considered.
April 08 FilegroupThe first edition of SQLServer I used is SQLServer 2000. Filegroup had existed at that time, but actually I don't start to explore this feature until these several days. Under default circumstance, the database engine would create one database data file and one log file both of which belong to the PRIMARY filegroup which is also the default filegroup if not specified. The main purpose of employing filegroup is to ease the burden of the database management typically including backup&restore activities. Filegroup usage with multiple disk drivers will gain performance improvement, for example, you have the sample table data spread accross three data file, A.ndf, B.ndf and C.ndf all of which reside in the same filegroup and have each of file reside on different disk driver. Then you will gain better I/O capacity and performance when the sample table data is accessed since the multiple disk heads will in paralle read these 3 drives. That's the reason behind the scene that employing filegroup improve performance.
Also you possibly use filegroup when do table partition during which you first create partition function to designate the partition range, then you create partition schema use the first steps' partition function and direct the database engine that data should go to different filegroups, thirdly you corelates the schema with the concreate table.
Go over the syntax for adding or modify filegroup(file)
use master;
go;
alter testdb;
add filegroup FG_1;
modify filegroup FG_1 default;
add file
(
name=Data1
filename=E:\demo\fg.ndf
size=10MB
maxsize=500MB
filegrowth=10MB
),
(
name=Data2
...
) to filegroup FG_1 March 24 positioned elementI am involved in the div+css layout design since it is so popular and is becoming standard for web front end UI design. Today I reread thru the 9th section of CSS2 on w3.org. this section is focus on the visual formatting model one of which is about positioned element typically about relative&absolute position. Here are several important statements excerpt from this section.
1. The containing block of one positioned box is established by the nearest positioned ancestor, or if none exists, the initial containing block.
so what's a positioned box? normally it is a block element like div with position css style attribute set to non static value. What's initial containing block? also in the above doc, it says the root of document tree generates the containing block, aka initial containing block.
2. In CSS2.1, a box may be laid out according three positioning schemes, normal flow, float and absolutely positioning. the relative positioning is included in the normal flow scheme, in the absolute positioning scheme, a box is removed from the normal flow entirely and assigned a position with respect to its containing block.
March 23 System.Data.SqlTypesDuring development of our management system, I built an utility class to read sql statement from several xml files. Each function module of system will be stored as one standlone file as such to ease maintenance task. In each file, I predefined sql statement schema for stored procedures and ordinary statements. To be concreate, each statement will correspond to one single element which has several attributes to describe its functionality and comments and has child element called params which has cascading child element param which in turn has four attribute to describe the parameter's name, size, type. All these seemed good and it worked fine for now. The problem was I used string value to assign this type attribute, though data type can be CLR's, can be SqlServer's, can be data provider's. Which one I should choose wisely? Today, I reread from MSDN about data type of CLR & native data type of SQL Server 2005 & mapped data type of Sqlserver data provider. Here I exepted some important words for memo:
The System.Data.SqlTypes namespace provide class for native data type of Sql Server, such as SqlDecimal, SqlDateTime, SqlString. The classes under this namespace have corresponding native data type of Sql Server and yield better performance than SqlDbType enumeration since behind the scene those data type conversion used SqlXXX types.
It's clear now. February 28 Lumisoft.Net & network security policyThis week, my focus and task is to test email attachment parsing functionality of our project. In this module, we used the third part open source software-LumiSoft.Net to monitor some designated email account, in a infinite loop, this component will connect to the email server with the correct email user account and password supplied, when the email arrived inbound the mailbox, this component will read the mail and save the annexes of mail to local directory, then the contents of the annex will be parsed by another module. Not difficult, is not it? initially I did think so.
quickly I finished my code:
Pop3_Client client=new Pop3_Client();
client.Connect("emailserverIpOrDomainname","port",false); --the third parameter designates whether use SSL connection
client.Authenticate("validuseremailaccount","password",false);
...
The interesting thing begin to happen immediately after I deployed my app into LAN circumstance. The app can correctly connect to our company's external email server, exchange server2007 and get the attachments. but it failed when testing in company's internal email server, exchange server2003. The thrown exception said this account is prohibited to log on to this computer. At first, I suspected that it must be related to email server settings. but I can't figure out concretely where, since I am not familiar to network security very much. It turned out finally that it is company's network security strategy causes this problem. Then internal LAN is based domain, the staff no of each emplyee is banged with his computer and it is not allowed that some employee log into the domain from other computer with his staff no. and the email server assigns every employee email account using his staff no, but on the email server, there is an option stating that this account which happens to be the account I used in code to connect to internal exchange server is allowed only.
This is a good lesson. I think. |
|
||||
|
|