Monday, March 29, 2010

03/29 : (ZT) SQL Server Stored Procedures Optimization Tips

 

SQL Server Stored Procedures Optimization Tips

1. Use stored procedures instead of heavy-duty queries.

This can reduce network traffic as your client will send to the server only the stored procedure name (perhaps with some parameters) instead of all the text from a large heavy-duty query. Stored procedures can be used to enhance security and conceal underlying data objects as well. For example, you can give the users permission to execute the stored procedure to work with restricted sets of columns and data.

2. Include the SET NOCOUNT ON statement in your stored procedures to stop the message indicating the number of rows affected by a Transact-SQL statement.

This can reduce network traffic due to the fact that your client will not receive the message indicating the number of rows affected by a Transact-SQL statement.

3. Call stored procedures using their fully qualified name.

The complete name of an object consists of four identifiers: the server name, database name, owner name, and object name. An object name that specifies all four parts is known as a fully qualified name.

Using fully qualified names eliminates any confusion about which stored procedure you want to run and can boost performance because SQL Server has a better chance to reuse the stored procedures execution plans if they were executed using fully qualified names.

4. Consider returning the integer value as a RETURN statement instead of returning an integer value as part of a recordset.

The RETURN statement exits unconditionally from a stored procedure, so the statements following RETURN are not executed. Though the RETURN statement is generally used for error checking, you can use this statement to return an integer value for any other reason. Using the RETURN statement can boost performance because SQL Server will not create a recordset.

5. Don't use the prefix "sp_" in the stored procedure name if you need to create a stored procedure to run in a database other than the master database.

The prefix "sp_" is used in the system stored procedures names. Microsoft does not recommend using the prefix "sp_" in user-created stored procedure names as SQL Server always looks for a stored procedure beginning with "sp_" in the following order: the master database, the stored procedure based on the fully qualified name provided, followed by the stored procedure using dbo as the owner (if one is not specified).

When you have the stored procedure with the prefix "sp_" in a database other than master, the master database is always checked first. If the user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.

6. Use the sp_executesql stored procedure instead of the EXECUTE statement.

The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improves readability of your code when many parameters are used.

When you use the sp_executesql stored procedure to execute a Transact-SQL statement that will be reused many times, the SQL Server query optimizer will reuse the execution plan it generates for the first execution when the change in parameter values to the statement is the only variation.

7. Use the sp_executesql stored procedure instead of temporary stored procedures.

Microsoft recommends using temporary stored procedures when connecting to earlier versions of SQL Server that do not support the reuse of execution plans. Applications connecting to SQL Server 7.0 or SQL Server 2000 should use the sp_executesql system stored procedure instead of temporary stored procedures in order to have a better chance of reusing the execution plans.

8. If you have a very large stored procedure, try to break down the stored procedure into several sub-procedures, and call them from a controlling stored procedure.

The stored procedure will be recompiled when any structural changes are made to a table or view referenced by the stored procedure (an ALTER TABLE statement, for example), or when a large number of INSERTS, UPDATES or DELETES are made to a table referenced by a stored procedure. So, if you break down a very large stored procedure into several sub-procedures, there's a chance that only a single sub-procedure will be recompiled, while other sub-procedures will not.

9. Try to avoid using temporary tables inside your stored procedures.

Using temporary tables inside stored procedures reduce the chance to reuse the execution plan.

10. Try to avoid using DDL (Data Definition Language) statements inside your stored procedure.

Using DDL statements inside stored procedures also reduce the chance to reuse the execution plan.

11. Add the WITH RECOMPILE option to the CREATE PROCEDURE statement if you know that your query will vary each time it is run from the stored procedure.

The WITH RECOMPILE option prevents reusing the stored procedure execution plan, so SQL Server does not cache a plan for this procedure and the procedure is always recompiled at run time. Using the WITH RECOMPILE option can boost performance if your query will vary each time it is run from the stored procedure, because in this case the wrong execution plan will not be used.

12. Use SQL Server Profiler to determine which stored procedures have been recompiled too often.

To check if a stored procedure has been recompiled, run SQL Server Profiler and choose to trace the event in the "Stored Procedures" category called "SP:Recompile". You can also trace the event "SP:StmtStarting" to see at what point in the procedure it is being recompiled. When you identify these stored procedures, you can take some correction actions to reduce or eliminate the excessive recompilations.

03/29: Interview Question

 

Question :

You are given an array of integers (both positive and negative). Find the continuous sequence with the largest sum. Return the sum.
EXAMPLE
input: {2, -8, 3, -2, 4, -10}
output: 5 [ eg, {3, -2, 4} ]

Answer :

public int GetMaxSumFromArray()

{

int maxsum;

int tempsum;

int [] a=new int[]{6, -8, 3, -2, 4,-10};

for (int i=1;i<=n;i++)

{

tempsum+=tempsum+a[i];

if (tempsum<0)

// if tempsum<0

 

{

tempsum=0;

}

//since the array has positive value, so maxsum can not be 0 , so the smallest value is 0

 

if(maxsum<tempsum)

{

maxsum=tempsum

}

}

return maxsum;

}

}

Saturday, March 27, 2010

03:27: Dispose Pattern In C# (ZT)

 

When we give application to client, we dont know how will he use that whether he will call dispose or not?
It may be missing at client side so our application should be smart enough to free used resources, here is code
which will give Idea to implement finalizer and dispose in same class to take care of resource cleaning.

 

class  DisposePatternInstance : IDisposable
{
private bool IsUnManagedResourceDisposed = false;

~DisposePatternInstance ()
{
Dispose(false); // means only clean up unmanaged resource
}

protected void Dispose(bool IsReleaseMangedResource)
{
if (IsReleaseMangedResource) // clean up managed resource
{
// Code to dispose the managed resources of the class
}


      


if( !IsUnManagedResourceDisposed) // clean up unmanaged resource if it is not released before
{


// Code to dispose the un-managed resources of the class


IsUnManagedResourceDisposed=true;


}




           }

public void Dispose()
{
Dispose(true); // to clean up both managed and unmaned resources



GC.SuppressFinalize(this); //If dispose is called already then say GC to skip finalize on this instance
}
}




 




  • Finalize() is implicitly clean up unmanaged resources (will be called implicitly in destructor of class. so it is a back up method  to make sure the unmanaged resources won’t leak  )


  • Dispose() is explicitly clean up unmanaged resources 



 



As an example, consider a class that holds a database connection instance. A developer can call Dispose on an instance of this class to release the memory resource held by the database connection object. After it is freed, the Finalize method can be called when the class instance needs to be released from the memory.



 



 









Thursday, March 25, 2010

03/25: (ZT)从面试题看高级软件工程师需要哪些技艺

 

 

1.B/S方面,
  简要介绍企业内部系统的设计需要注意哪些问题.
   然后就提到的性能,安全,可扩展性,可用性等非功能性特性中的一点或几点深入的讨论

A:

  • First of all, must meet functional requirement after analysis
  • During design, have the following concerns
    • performance
    • scalability
    • extensibility
    • security
    • easy maintenance
      • coding rule
      • name convention
  • Can use agile development methodology for frequent requirement change project.
    • Scrum
    • TDD


2.数据库性能问题
  数据库设计一般需要注意哪些
  索引如何设计
  如何快速定位在较高负载时造成性能问题的存储过程或查询语句
  你自己一个功能较复杂的存储过程,如何评估它的效能,以及达到什么样的标准才签入到产品中
3.设计
  关于组件对外提供的接口,需要注意哪些
  工作中用过哪些设计模式及面向对象设计的原则,有过有用过的话,有没有相对较难但效果很好的实际应用
4.测试
  有过自动化测试的经验吗,如果有的话,简单介绍下具体操作.
5.解决问题
  如果忽然碰到很棘手,而且从来没接触过的问题,你一般会怎么解决
  详述如你在项目快发布的时候被测试出如第三方组件奇怪问题,64位兼容,硬件调用等从没接触过且资料较少的Bug,该怎么解决
6.其他
  有没有看过一些给你触动很大的面向对象设计的书籍,有的话简单介绍一下该书的大致内容以及印象很深刻的一部分
  如果之前承诺的发布日期就在两周后,但你发现你负责的模块需要三周才能完成.你会怎么做
  假如你想申请延期或砍功能,你怎么说服经理
  某测试小组成员老将测试你负责部分中出现的Bug直接提交到高层,且经常在你比较忙的时候请教你负责模块的内容.对于这种情况,你打算如何处理
如果是你碰到了上述面试,你认为对方主要考察的是哪些方面,是你的话如何回答

Wednesday, March 24, 2010

03/24: ASP.Net Caching Mechanism

 

  • Page Caching:
    • Add the following on the head of *.aspx
    • <%@ OutputCache Location="Server" Duration="60" VaryByParam="sdy;sdy1" %>

      • It means the page will only be updated only if page cache duration expired or two parameters sdy and sdy1 are changed.
      • Link : http://test.aspx?sdy=1 & sdy1=2

03/24: Common FCL

(ZT)

net程序员应该掌握的常用类库

系统类

Type类,Object类,String类, Arrary类,Console类, Exception类,GC类, MarshalByRefObject类, Math类。

DateTime结构,Guid 结构,

     ICloneable接口,IComparable接口,IConvertible接口, IDisposable类,

集合类

ICollection接口,IComparer接口,IDictionary接口。IDictionaryEnumerator接口 ,IEnumerable接口,

      IEnumerator接口,IHashCodeProvider接口,IList接口,

     Stack 类,Queue类 ArraryList类,Hashtable类,SortedList类 CollectionBase类,DictionBase类

     DictionEntry结构。

输入输出

字节流

Stream类,BufferedStream类,FileStream类,MemorStream类

二进制I/O流

BinaryReader类,BinaryWriter类。

字符I/O流

     TextReader类,TextWriter类,StreamReader类,StreamWriter类,StringReader类,StringReader类,StringWriter类。

I/O枚举

FileAccess枚举,FileAttributes枚举,FileMode枚举,FileShare枚举。

文件系统操作类

FileSystemInfo类 Directory类,Directoryinfo类 ,File类,Fileinfo类

反射

应用程序层次结构类

  Assembly类,Module类,

成员信息类

Memberinfo类,MethodBase类,ConstructorInfo类,EventInfo类

  MainifestResourceInfo类 Methodinfo类,ParameterInfo类,propertyInfo类

       SystemReflection的其他成员,

Binder类,BindingFlags枚举 IReflect枚举 Pointer类

文件操作

Encoding类 ,AscIIEndoing类,UnicodeEncoding类,

UTF7Encoding类 UTF8Encoding类,Decoder类

StringBuilder类

正则表达式

Capture类

CaptureCollection类

Group类

Match类 MatchCollection类

Regex类

RegexOptions枚举

多线程

Thread类,Monitor类,WaitHandle类,Mutex类 ReaderWriterLock类。ThreadPool类,Timeout类,

InterLocked类,

ThreadStart委托、

ThreadPriority枚举,ThreadState枚举,

Monday, March 22, 2010

03/22: Create An External Library In .Net And Call It In Smarteam

 

 

Development Environment Setup

  • Copy all files of Smarteam’s Assembly from Windows GAC to a specified  folder (C:\Program Files\SmarTeam\Bin\Assembly)
  • Register this folder under window registry

 

Copy.bat

if not exist "C:\Program Files\SmarTeam\Bin\Assembly" md "C:\Program Files\SmarTeam\Bin\Assembly"
for /R %WINDIR%\assembly\GAC_32 %%f in (SmarTeam.Std.*.dll) do copy  %%f  "C:\Program Files\SmarTeam\Bin\Assembly"
call regedit /s RegisterSmarTeamAssemblies.reg

copy "C:\Program Files\SmarTeam\Bin\DRLTools\*.dll"  "C:\Program Files\SmarTeam\Bin\Assembly"
pause

 

RegisterSmarTeamAssemblies.reg

Windows Registry Editor Version 5.00
(c) 2006 SmarTeam Corp. Ltd

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\SMARTEAM]
@="C:\\Program Files\\SMARTEAM\\Bin\\Assembly"

 

 

Steps :

  • Create a library file .net
  • Add some smarteam reference
  • Add class files
    • Application.vb

        Option Explicit On
        Imports SmarTeam.Std.Interop.SmarTeam
        Imports SmarTeam.Std.Constants

        Public Class Application

            Public Function MyExample(ByRef SmSession As SmApplic.SmSession, ByRef FirstRec As SmRecList.SmRecordList) As Short
                With New clsExamples
                    MyExample = IIf(.MyExample(SmSession, FirstRec), BFERRPUB.Err_None_N, BFERRPUB.Err_Gen_N)
                End With
            End Function

        End Class

    • clsExample.vb

        Option Explicit On
        Imports SmarTeam.Std.Interop.SmarTeam
        Imports SmarTeam.Std.Constants

        Friend Class clsExamples

            Public Function MyExample(ByRef SmSession As SmApplic.SmSession, _
                        ByRef FirstRec As SmRecList.SmRecordList) As Boolean
                MsgBox("My login name is: " & SmSession.UserMetaInfo.UserLogin & vbNewLine & _
                       "There were " & CStr(FirstRec.RecordCount) & " objects selected.", _
                        MsgBoxStyle.Information, BFCOMPUB.NM_OUR_COMPANY_NAME)
                MyExample = True
            End Function
        End Class

  • Add a strong key and Sign this assembly
  • Deploy to server:
    • Register:
      • "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\RegAsm.exe" "C:\Customize2\Exercise 3\bin\DSSimpleTest..dll" /codebase
    • Unregister:
      • "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\RegAsm.exe" "C:\Customize2\Solution 1\bin\DSSimpleTest..dll" /unregister
  • Write script function to invoke this dll
    • sdytest.ebs

        Option Explicit
        '    This file contains sample functions for the Customize 2 training
        '
        '    (c) 2006 SmarTeam Corp. Ltd
        '

        '=======================================================================================
        '    This function can be hooked as a user defined tool and demonstrates the usage
        '    of the Smart Basic Editor combined with a COM object
        '
        Function SDExample (ApplHndl As Long,Sstr As String,FirstPar As Long,SecondPar As Long,_
                             ThirdPar As Long ) As Integer
            Dim SmSession     As SmApplic.SmSession
            Dim FirstRec    As Object
            Dim DSSimpleTest    As Object
            '
            '    Get the session and get the selected data
            Set SmSession = SCREXT_ObjectForInterface(Applhndl)
            CONV_RecListToComRecordList FirstPar, FirstRec
            '
            '    Create a connection to our own object
            Set DSSimpleTest = CreateObject("DSSimpleTest.Application")
            ' Note : Namespace_Name.Class_name of .net code
            '    Now call the method - procedure or function
            DSSimpleTest.MyExample SmSession,FirstRec
            '
            '    Release the dll object
            Set DSSimpleTest = Nothing
        End Function

    • Copy this file to smarteam script folder
    • In script maintenance  of admin console, invoke function with hooked event

Friday, March 19, 2010

03/19: Design Pattern in .Net

 

Example :

DP is  a practical optimized design solution .  General speaking, if a language is more advantaced and has more support to OOP,then using dp will be more easily. Just like .Net , a lot of dp is used inside:

 

Example

  1. Adding Reference : Proxy
  2. Net中对WebRequet、Stream等抽象类的继承扩展 : Decoration
  3. Asp.net Page Initialization: HttpApplication: Singleton
  4. IEnumerable: Iterator
  5. IEnumerable.GetEnumerator : Abstract Factory

Monday, March 15, 2010

03/15: CLR Threading Pool

 

When CLR initializes, the thread pool has no thread and the task queue of the pool is empty. When this queue is not empty,threading pool will create / kill  thread dynamically based on the tasks inside of queue..

In my mind

Threading pool is like an optimized system thread component which can be used by developer. Developer don’t need to know much detail about this implementation. Developer can just use it to do thread management efficiently.

 

Two kinds of threads in this pool

  • Work threads are used when your application asks the thread pool to perform an asynchronous computer-bound operation (which can include initiating an I/O-bound operation).
  • I/O threads are used to notify your code when an asynchronous I/O-bound operation has completed. Specifically, this means that you are using the Asynchronous Programming Model (APM) to make I/O requests such as accessing a file, networked server, database, Web service, or other hardware device

Thursday, March 11, 2010

03/11: (ZT) How to improve Asp.net Performance

 

From :

http://www.soaspx.com/dotnet/asp.net/tech/tech_20090828_211.html

一、SqlDataRead和Dataset的选择

Sqldataread优点:读取数据非常快。如果对返回的数据不需做大量处理的情况下,建议使用SqlDataReader,其性能要比datset好很多。缺点:直到数据读完才可close掉于数据库的连接 (SqlDataReader 读数据是快速向前的。SqlDataReader 类提供了一种读取从 SQL Server 数据库检索的只进数据流的方法。它使用 SQL Server 的本机网络数据传输格式从数据库连接直接读取数据。DataReader需及时显式的close。可及时的释放对数据的连接。)

Dataset是把数据读出,缓存在内存中。缺点:对内存的占用较高。如果对返回的数据需做大量的处理用Dataset比较好些可以减少对数据库的连接操作。优点:只需连接一次就可close于数据库的连接

一般情况下,读取大量数据,对返回数据不做大量处理用SqlDataReader.对返回数据大量处理用datset比较合适.对SqlDataReader和Dataset的选择取决于程序功能的实现。

二、ExecuteNonQuery和ExecuteScalar

对数据的更新不需要返回结果集,建议使用ExecuteNonQuery。由于不返回结果集可省掉网络数据传输。它仅仅返回受影响的行数。如果只需更新数据用ExecuteNonQuery性能的开销比较小。

ExecuteScalar它只返回结果集中第一行的第一列。使用 ExecuteScalar 方法从数据库中检索单个值(例如id号)。与使用 ExecuteReader 方法, 返回的数据执行生成单个值所需的操作相比,此操作需要的代码较少。

只需更新数据用ExecuteNonQuery,单个值的查询使用ExecuteScalar

三、数据的绑定DataBinder

一般的绑定方法<%# DataBinder.Eval(Container.DataItem, "字段名") %>

用DataBinder.eval 绑定不必关心数据来源(Dataread或dataset)。不必关心数据的类型eval会把这个数据对象转换为一个字符串。在底层绑定做了很多工作,使用了反射性能。正因为使用方便了,但却影响了数据性能。

对数据的绑定建议使用<%# ctype(Container.DataItem,DataRowView).Row["字段名"] %>。数据量大的时候可提高几倍的速度。使用时注意两方面:

1.需在页面添加<%@ Import namespace="System.Data"%>.

2.注意字段名的大小写(要特别注意)。如果和查询的不一致,在某些情况下会导致比<%# DataBinder.Eval(Container.DataItem, "字段名") %>还要慢。如果想进一步提高速度,可采用<%# ctype(Container.DataItem,DataRowView).Row(0) %>的方法。不过其可读性不高。

四、使用存储过程

性能方面:存储过程提供了许多标准sql语言中所没有的高级特性。其传递参数和执行逻辑表达式的功能,有助于应用程序设计者处理复杂任务。另外,存储过程存储在本地服务器上,减少了执行该过程所需的网络传输宽带和执行时间。(存储过程已经对sql语句进行了预编译,所以其执行速度比在程序里执行sql语句快很多)

程序结构方面:从程序的可扩展性看,使用存储过程会对程序以后的修改带来方便。比如数据库的结构改变了,只需修改相对应的存储结构,和程序中的调用部分即可。

五、大量查询时使用分页查询

如果我们有大量的数据要查询,但是显示的时候是一页一页的显示,这是我们可以用分页查询的功能,就是需要多少数据就查询多少数据,这样至少可以从两个方面优化速度:

1. 传输的数据少,可以减少带宽的压力。

2. 由于查询的数据少,可以减少数据库的查时间。

六、EnableViewState(页面的视图状态)。如果无特殊要求设置为false。

他主要是用于维护页面的 UI 状态,Web 是没有状态的,ASP.NET 页面也没有状态,它们在到服务器的每个往返过程中被实例化、执行、呈现和处理,因此他的存在是要消耗服务器的性能的,当然他的存在也可以减少我能很多的代码,因为很多控件的状态他帮我们维护了,在不需要维护状态的情况下完全可以禁用viewstate。

如下所示:

单个页面:<%@ Page EnableViewState="False" %>

所有的页面:在 web.config 中 <Pages EnableViewState="false" />

七、Html控件和服务器控件的选择

服务器控件带来的方便和功能上的实现是html控件所不能比拟的。但是是以牺牲服务器端的资源来取得的。我个人建议:如果html控件达不到所要实现的功能,而且和一些脚本语言(如javascrpt/vbscript)结合也不能实现的话,才会选择服务器控件。

主要针对几个常用数据控件说明一下:

DataGrid:自带最强大的数据显示控件,内置了对数据的修改、删除、添加、分页等很多实用功能。如果你只需对数据显示的话,尽量不要选择DataGrid(它把数据都存储在viewstate中),也不要使用自带的分页功能,microsoft在自动分页的底层做了很多工作,虽然使用方便了,但性能开销大了。

DataList:比DataGrid功能少了很多。但自定义性强了很多。特有的多行数据显示,给我们带来了很多方便。DataGrid能实现的功能,它基本能实现,所以建议使用它。

Repeater:功能最少,但自定义性非常强。如果只需对数据显示,建议使用。由于减少了很多功能,对服务器的性能带来消耗最小。因此,如果是对数据显示的话,我基本上都是选择 Repeater然后DataList最后DataGrid 尽量选择html控件,能在客户端实现的功能就在客户端实现(熟练掌握javascript),减少服务器的压力。数据控件选择顺序:Repeater、DataList、DataGrid 。

八、String和StringBuilder的比较

String类对象是不可改变的,对于String对象的重新赋值在本质上是重新创建了一个String对象并将新值赋予该对象,其方法ToString对性能的提高并非很显著。

在处理字符串时,最好使用StringBuilder类,其.NET 命名空间是System.Text。该类并非创建新的对象,而是通过Append,Remove,Insert等方法直接对字符串进行操作,通过ToString方法返回操作结果。

03/11: SP Workflow With Infopath Form

Scenario : during a workflow process, when a user is assigned a task to approve or reject request, he will see a infopath form like the following :

image

Then this user will send response back to workflow

 

Step 1 :  Create a info path form from infopath 2007 of office

  • Create form, data connection, add status field of connection
  • Add following actions for rules of both “Accept” and “Reject” btton
    • set status field
    • submit data to data connection
    • close a form
  • Set the Security Level of the form to Domain (menu Tools-Forms Option-Security and Trust) :
  • publish form ( copy *.xsn file to %programfiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\project file \ . So the first folder put something like “%programfiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\project file \*.xsn”. The second folder make is empty. Might see some warning message. After publishing, *.xsn will be copied to system folder.
  • get form ID property value and copy to workflow .xml

      <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Workflow
        …
           TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160"
           >
          <Categories/>
          <MetaData>
            …      
            <Task0_FormURN>urn:schemas-microsoft-com:office:infopath:ApproveReject:-myXSD-2007-07-06T16-16-03</Task0_FormURN>
          </MetaData>
        </Workflow>
      </Elements>

  • deploy workflow.

 

Can see detail from following link :

 

http://sergeluca.spaces.live.com/blog/cns!E8A06D5F2F585013!936.entry

       

Wednesday, March 10, 2010

03/10: Smart Team | C++ In WCE

 

User Defined Tool :

Sample Function to show ID:

 

Function ShowID(ApplHndl As Long,Sstr As String, _
            FirstPar As Long, SecondPar As Long, ThirdPar As Long ) As Integer

    Dim rlFirstRec            As Object
    Dim DataRecord             As Object
    Dim ID                    As String
    Dim Description         As String

    'Convert the first recordlist parameter to a SmRecordList
    CONV_RecListToComRecordList FirstPar, rlFirstRec

    'Get the first record from the SmRecordList

   ‘ Be sure to put Set there . waster a few hours for missing set
    Set    DataRecord = rlFirstRec.GetRecord(0)

    'Get attributes
    ID = DataRecord.ValueAsString("TDM_ID")
    Description =  DataRecord.ValueAsString("TDM_DESCRIPTION")

    'Display the part ID
    Msgbox "The object: " & ID & " " & Description, ebInformation, "SMARTEAM"

    ShowID = Err_None   

End Function

 

 

See

Windows Mobile使用Native C++开发多线程程序

http://www.cnblogs.com/procoder/archive/2010/03/11/Multithreading-native-cpp.html

Tuesday, March 02, 2010

03/02: String.Format && StringBuilder && String.Concat Performance

 

The performance for string.format is not good. Its allows code to be more easily localized.

  • string.Format takes LOT OF TIME. It has to parse the string, replace in that strings str1,str2 and str3. It's 3-4 times slower than concatenation.
  • String.Format() actually creates a StringBuilder and calls StringBuilder.AppendFormat()! String.Format() is implemented like this:

String.Concat is better for performance.

(ZT:http://blog.csdn.net/zhanglei5415/archive/2007/07/23/1703256.aspx)

以下两段语句最终效果均为用数据库插入数据,请先对比观察它们的不同:

string sql = string.Concat(new object[] {"insert into 表名(字段1,字段2) values('",值1,"','",值2,"')"});

string sql = "insert into 表名(字段1,字段2) values('"+值1+"','"+值2+"')";

以上两条语句的结果是相同的,但采用string.Concat()可以使用程序的执行效率显著提高,所以,建议拼串的操作都采用string.Concat来实现。

 

 

Conclusion

String.format< stringbuidler.append (as string.format will  call stringbuilder.append)<String.concate

02/28: SP Custom Activity

 

Deploying Custom Activity: After creating activity

  • Sign the activity
  • Run “ gacutil.exe –i *.dll”  to deploy component to gac

Without deployment, the other component using this activity will be failed in server.