ASP.NET technology FAQ

xiaoxiao2021-03-31  212

1. Introduction 1.1 What is .NET? 1.2 .NET is just a new name for Windows DNA? 1.3 .NET applies only to establish a web site? 1.4. When did you announce? What will I be released at 1.5 .NET? 1.6 How to develop .Net Application 1.7 Where can I download .NET SDK and Visual Studio 7? What is the key technologies in .NET? 1.9 .NET framework will run on what platform? 1.10 .NET framework support? 1.11 .NET framework meets standardization trends? 2. Basic term 2.1 What is CLR? 2.2 What is CTS? 2.3 What is CLS? 2.4 What is IL? 2.5 What is C #? 2.6 What is the meaning of "managed" in .NET category. 2.7 What is an image? 3. Component 3.1 What is component? 3.2 How to create components? 3.3 What is the difference between private components and shared components? 3.4 How does the component find each other? 3.5 How does the component version work? 4. Application Domain 4.1 What is the application domain? 4.2 How to create AppDomain? 4.3 Can I write my own .NET host? 5. Garbage collection 5.1 What is garbage collection? 5.2 After the last reference to the object is canceled, it does not necessarily be destroyed immediately, right? 5.3 Why doesn't you provide a sectative destructure? 5.4 Is there a problem with the lack of determination in .NET? 5.5 Determination of destructure affects the use of COM objects in managed code? 5.6 I have heard that I should avoid using the Finalize method, then should I achieve Finalize in my class? 5.7 Do I have a means of controlling garbage collection algorithms? 5.8 How do I know what the garbage collector is doing? 6. Attribute 6.1 What is the property? 6.2 Can I create my own metadata properties? 6.3 Can I create my own context attribute? 7. Code Access Security 7.1 What is Code Access Security (CAS)? 7.2 How does Cas work? 7.3 Who defines the CAS code group? 7.4 How to define your own code group? 7.5 How to change the authority set of code group? 7.6 Can I create my own permissions? 7.7 How do you diagnose your own procedure when there is a problem? 7.8 I can't stand the trouble brought by CAS, can I turn off it? 8. Intermediate Language (IL) 8.1 Can I see the middle language of the component? 8.2 Can I get the source code from IL by reverse engineering? 8.3 How to prevent someone from get my code through the reverse engineering? 8.4 Can I use IL to program directly? 8.5 IL can do something you can't do in C #? 9. Did the COM 9.1 COM die? Did the DCOM died? 9.3 MTS / COM done? 9.4 Can I use COM components in .NET? 9.5 Can you use the .NET component in COM? 9.6 Is ATL in the world of .NET? 10. How does the remote calculation of. NET? 10.2 How to get Win32 API in .NET?

11. Class library 11.1 file I / O 11.1.1 How to read text files? 11.1.2 How to write a text file? 11.1.3 How to read a binary? 11.1.4 How to delete a file? 11.2 Text Process 11.2.1 Does the regular expression are supported? 11.3 Internet 11.3.1 How to download the web? 11.3.2 How to use proxy servers (Proxy)? 11.4 XML 11.4.1 Does DOM? 11.4.2 Do you support SAX? 11.4.3 Do you support xpath? 11.5 Thread 11.5.1 Do you support multithreading? 11.5.2 How to generate a thread? 11.5.3 How to stop a thread? 11.5.4 How to use a thread pool? 11.5.5 How do I know when my thread pool work project is completed? 11.5.6 How to prevent concurrent access to the data? 11.6 Tracking 11.6.1 Is there a built-in tracking / log support? 11.6.2 Can I redirect the tracking output to a file? 11.6.3 Can you customize the output of tracking? 12. Resources 12.1 Where can I get details about .NET? 12.2 Sample Code and Utilities 1. Introduction 1.1 What is .NET? It's hard to use a sentence. According to Microsoft, .NET is a "revolutionary new platform, built on open Internet protocols and standards, combining calculations and communications together with a new way through tools and services."

More practical definitions are: .NET is a new environment for developing and running software, making it easy to develop web-based services, have rich runtime services to support components written in multiple programming languages, have a cross-language and cross-platform Interoperability.

Note that when the term ".NET" is used herein, it refers only the new .NET runtime and related technologies. Sometimes we also call it ".NET framework." This article does not include any other Microsoft to add any existing products and techniques (such as SQL Server.Net) that add .NET names.

1.2 .NET is just a new name for Windows DNA? Do not. In many places, Windows DNA merely refers to the market terminology of a way to use the prior art (that is, the so-called three-order path). .NET is more urgent and includes a complete software development and runtime framework.

1.3 .NET applies only to establish a web site? Do not. If you write any Windows software (using ATL / COM, MFC, VB or even Win32 bare interface), Net may provide a feasible selection (or supplement) for what you are doing. Of course, if you are developing a web site, .NET has many things that make you interested - not just asp .

1.4. When did you announce? On the Forum 2000 Forum held on 22 June 22, 2000, Bill Gates made a speech and taught the "foreground" of .NET. PDC meetings in July 2000 made a lot of talks on .NET technology, the talk representative got the CD which contains the .NET Framework / SDK and Visual Studio 7 preview.

What will I be released at 1.5 .NET? It is expected to be in the second half of 2001.

1.6 How to develop .NET applications? The .NET Framework SDK contains a command line compiler and utility that can be used to create .NET applications. The next version of Visual Studio (called Visual Studio 7 or Visual Studio.net) will fully integrate support for .NET development. 1.7 Where can I download .NET SDK and VISUAL STUDIO 7? From http://msdn.microsoft.com/net, you can download the SDK's Beta 1. If you are a MSDN Universal subscriber, you can also download the Beta 1 version of Visual Studio 7.

What is the key technologies in .NET? ASP.NET, CLR (Common Language Runtime-General Language Runture), C # (New Generation Class-Java Language), SOAP, XML, ADO.NET, Multi-Language Support (Eiffel, Cobol, etc.)

1.9 .NET framework will run on what platform? Beta 1 supports development on Windows 2000, NT4 SP6A, Windows ME, and Windows 98. Windows 95 supports runners.

Microsoft will publish a new version of Windows as a schedule similar to the .NET run library. Its code is "WHistler", which is largely an expansion update of Windows 2000, which has important changes to GUI. Microsoft will be ".NET-enabled" as a new operating system's selling point, but it seems to be tied together with the .NET run library. If .NET runs can be completed in time, it will be included within the Whistler; otherwise, Whistler will ship separately.

1.10 .NET framework support? Start Microsoft will provide C #, C , VB, and JScript compilers. Other suppliers announced they intentionally develop .NET compilers like Cobol, Eiffel, Perl, SmallTalk, and Python.

1.11 .NET framework meets standardization trends? C # and recommendations for some things called "Universal Language Infrastructure" have been submitted to ECMA. See http://msdn.microsoft.com/neet/ecma/

2. Basic term 2.1 What is CLR? CLR = Common Language Runtime-General Language Runture. The CLR is a set of standard resource collections, regardless of the programming language, all (theoretical) .NET programs can benefit from it. Robert Schmidt (Microsoft) lists the following CLR resources in his MSDN PDC # article:

Object-oriented programming model (inheritance, polymorphism, abnormal processing, garbage collection) security model type system All .NET basic class Many.net framework class development, debugging and assessment tool running and code management IL-machine language converter and optimization Be aware of

These meanings are, in the .NET world, different programming languages ​​will be more equivalents more than the past, although it is obvious that all CLR services are supported by all languages.

2.2 What is CTS? CTS = CommON Type System-General Type System. It refers to a series of types that the .NET runtime is understood and then the .NET application can use. However, beware that not all .NET languages ​​will support all types in the CTS. CTS is a super-collection of CLS.

2.3 What is CLS? CLS = Common Language Specification - General Language Specification. It is a subset of a CTS that is expected to support all .NET languages. This idea is to let any programs that use the CLS-compatible type and the .NET program written in any language can be operated.

It is theoretically to allow close interoperability between different .NET languages ​​- for example, allowing a C # class to be inherited from one VB class.

2.4 What is IL? IL = intermediate language language - intermediate language. Also known as MSIL. All .NET source code (using any language) is compiled into IL. The IL is then converted to a machine code in the installation point of the software.

2.5 What is C #? C # is a new language running in the .NET framework. In their "C # Introduction" white paper, Microsoft describes C #:

"C # is a simple, object-oriented, and is a type of safe modern programming language. C # (pronounced 'c sharp') is firmly rooted in the tree of C and C families, Soon for C and C programmers. C # help developers combine Visual Basic's high productivity and C direct control capabilities. "

Change the "C #" in the above introduction to "Java", you will find this statement is still correct :).

If you are a C programmer, you may want to see my C # FAQ.

2.6 What is the meaning of "managed" in .NET category. The term "managed" has led to a lot of misunderstandings. It uses it in different places in .NET, it refers to different things that are different from each other.

Managed Code: The .NET Framework provides several core running services to running procedures, such as exception handling and security. In order for these services to work, the code must provide some information about the lowest level of runtime. Such code is called managed code. By default, all C #, Visual Basic.Net and JScript.net code are managed. If it is not specified, the VS7 C code is not managed, but can generate the compiler to generate the managed code through a command line switch (/ COM ).

Managed data: refers to data assigned and recycled by the garbage collector of the .NET run. C #, VB.NET and JScript.net data are always managed. Even if the / COM switch is used, the VS7 C data is not managed by default, but it can be specified as managed data using the __gc keyword.

Manage class: usually involved in the C Managed Extensions (ME) category. When using ME C , you can specify it as managed by the __gc keyword. The name is actually, the memory occupied by the instance of this class is managed by garbage collector, but not so. This class has become a full .NET group member, which brings benefits and restrictions. One of the benefits is to obtain interoperability between classes written in other languages ​​- for example, an administrative C class can inherit the VB class. One of the limits is that the management class can only inherit a base class.

2.7 What is an image? All .NET compilers produce special data defined in the modules they generated. These special data are encapsulated with modules (subsequent modules are encapsulated into components), and can be accessed by mechanisms called images. The System.Reflection namespace contains classes that ask the module or components to ask them.

Using the image to access the special data of .NET. Nothing to access the type library data used in the COM using iTyPelib / ITYPEINFO, and the purpose of use is similar -, for example, determine the data type size, to schedule between the context, process, the boundary between the machine they.

The image can also be used to dynamically call the method (see System.Type.InvokeMember), even dynamically create a type (see System.Reflection.Emit.Typebuilder) even during runtime.

3. Component 3.1 What is component? Components are sometimes described as a logically .exe or .dll, it can be any application (with a primary entry point) or library. A component consists of one or more files (DLL, EXE, HTML files, etc.) indicating a set of resources, type definitions, and these types of implementations. One element can also include references to other components. These resources, types, and references are described in a data block called a list. The list is part of the component, so that components are described herein. An important aspect of components makes them part of a type of unique logo. The unique marker of the type is got together with the components and type names thereof. This means, for example, if the element A outputs a type called T, the component B outputs a type also known as T, and the .NET runtime will be considered a completely different types. In addition, don't confuse the components and namespaces - namespace is just a hierarchical approach to the organization type name. For running libraries, the type name is the type name, whether or not the name. From the running library, it is the only type of the type name (regardless of the type name belonging to which name space).

The components are also important in the security of .NET - Many security limits are implemented on the boundary of the component.

Finally, the component is the version controlled in .NET - see below for details.

3.2 How to create components? The easiest way to create components is to use the .NET compiler directly. For example, the following C # program:

Public class ctest {public Ctest () {system.console.writeline ("Hello from ctest");}} can be compiled into a library element (DLL) with the following method:

CSC / T: library ctest.cs You can see the contents of the component by running the "IL Anti-assessment" tool belled by the .NET SDK.

In addition, you can also compile your source code into modules, then use the component connector (Al.exe) to combine the module into a component. For the C # compiler, the / target: Module switch can specify a module instead of the component.

3.3 What is the difference between private components and shared components? Spatial allocation and visibility: Private components are usually used by an application, which is stored below this application or subdirectory below. Sharing elements are typically stored in a global component buffer, which is the storage of components maintained by .NET running. Sharing elements are usually the code base to be used in many applications, such as .NET Framework classes. Version Control: The runtime is only implemented on the shared component, not the private component.

3.4 How does the component find each other? By looking for a directory path. There are several factors that affect the path (such as AppDomain host, application profile, etc.), but for private components, search paths are usually the application's directory and their subdirectory. For shared components, search paths are usually the same as private components, plus shared component buffers.

3.5 How does the component version work? Each component is represented by a version number called a compatibility version. Similarly, references to components (from another component) include names and versions of the referenced components.

The version number has four digital parts (for example, 5.5.2.33). Elements that are not the same in the first two parts are considered incompatible. If the top two are the same, the third part is different, and components are considered "possible." If only the fourth part is different, the component is considered compatible. However, this is just the default guidelines - is the scope of the version policy decision to apply these rules. Version Policy can be specified in the application configuration file.

Remember: The version control is only for shared components, not the private component.

4. Application Domain 4.1 What is the application domain? AppDomain can be seen as a lightweight process. There can be multiple Appdomain in a Win32 process. The main purpose of AppDomain is to separate applications and other applications. By using a separate address space, the Win32 process provides isolation. This method is effective, but the overhead is very large and the telescopic is not good. The .NET runtime is managed by controlling memory by controlling all memory used to apply AppDomain isolation -AppDomain, so the run library ensures that the APPDOMAIN cannot access each other's memory.

4.2 How to create AppDomain? Appdomains usually have host creation. The host includes Windows Shell, ASP and IE. When you run a .NET application from the command line, the host is the shell. Shell Creates a new AppDomain for each app.

AppDomains can also be explicitly created by .NET applications. Here is a C # example of creating appdomain, which creates an instance of an object, and then performs a method of the object:

Using system; using system.runtime.remoting;

Public class cappdomaininfo: MarshalByrefObject {public string getAppdomainInfo () {return "Appdomain =" Appdomain.currentDomain.FriendlyName;}

}

public class App {public static int Main () {AppDomain ad = AppDomain.CreateDomain ( "Andy's new domain", null, null); ObjectHandle oh = ad.CreateInstance ( "appdomaintest.exe", "CAppDomainInfo"); CAppDomainInfo adInfo = (Oh.unwrap ()); string info = adinfo.getAppdomainInfo (); console.writeline ("Appdomain Info:" info); return 0;}}

4.3 Can I write my own .NET host? can. Regarding how to do, see the source code of the DM.NET Moniker developed by Jason Whittington and Don Box (http://staff.develop.com/jasonw/clr/readme.htm). There is also a code example called Corhost in .NET SDK.

5. Garbage collection 5.1 What is garbage collection? Garbage collection is a system that runs the library components through it to manage objects of the object's survival cycle and their occupied stacks. For .NET, it is not a new concept - Java and many other languages ​​/ run libraries have been used for a while.

5.2 After the last reference to the object is canceled, it does not necessarily be destroyed immediately, right? Yes it is. The garbage collector does not provide destruction of objects and is a time guarantee for the memory.

About the unclear objects in C #, Chris Sells has an interested clues: http://discuss.develop.com/archives/wa.exe? A2 = Ind0007 & l = DOT & P = R248192000 October Microsoft's Brian Harry posted a long analysis of this problem: http://discuss.develop.com/archives/wa.exe? A2 = ind0010a & l = DOTNET & P = R28572

Chris Sells Answer to Brian Posts here: http://discuss.develop.com/archives/wa.exe? A2 = Ind0010c & l = DOTNET & P = R983

5.3 Why doesn't you provide a sectative destructure? Because of the garbage collection algorithm. The .NET's garbage collector works through the list of all objects that are currently being used. All unrecognized objects during the scan can be destroyed and released. When the last reference to the object is canceled, this implementation of the algorithm makes the running library unable to get notifications - it can only discover when the next cleaning stack.

Moreover, this algorithm performs garbage collection as little as possible to work most efficient. Typically, the consumption of the stack capacity triggers the collection process.

5.4 Is there a problem with the lack of determination in .NET? This does affect the design of the component. If your object requires expensive or shortage resources (such as locking the database), you need to provide some way to let the client tell the object after work. Microsoft recommends that you should provide a method called Dispose () for this purpose. However, this will cause problems in a distributed object - who calls the dispose () method in a distributed system? There is a need for some form of reference-counting mechanism or owner management mechanism to handle distributed objects - unfortunately, the run library is loved to this.

5.5 Determination of destructure affects the use of COM objects in managed code? Yes it is. When using COM objects from managed code, you actually rely on garbage collectors to eventually release your object. If your COM object has expensive resources and can only be released after the event is finally released, you may need to provide a new interface on your object to support explicit DISPOSE () methods.

5.6 I have heard that I should avoid using the Finalize method, then should I implement Finalize in my category? For the garbage collector, the object with the Finalize method is more work than the object that does not have this method. It also does not guarantee the order of Finalized, so there is a different view for accessing other objects from a Finalized method. Finally, it cannot guarantee that the finalized method will be called. So, never rely on it to clean up the resources of the object.

Microsoft recommends the following ways:

Public class ctest {public override void dispose () {... // cleanup activities gc.suppressFinalize (this);} protected override void finalize () {dispose ();}} Under normal circumstances The resource is released, and the garbage collector is exempted from Finalize's obligation by calling suppressFinalize (). In the most unfavorable case, that is, the client has forgotten to call Dispose (), there is a large chance to call Finalize () to finalize the resources of the object via the garbage collector. Due to the defects of the garbage collection algorithm, this looks like a fairly reasonable handling method. 5.7 Do I have a means of controlling garbage collection algorithms? A little. The System.gc class provides a pair of interesting methods. The first is a Collect method - it enforces the garbage collector to immediately collect all untruritable objects. The other is RequestFinalizeOnShutdown (), which tells the garbage collector to run the femalize () method for each object when the application is shut down. When the application is closed, the garbage collector generally selects a quick launch method rather than calling Finzlize (), so this method can manually force the library to negative a little responsibility.

If you want to verify this is not just theoretical saying, it is a test program below:

Using system;

Class Ctest {Protected Override Void Finalize () {Console.Writeline ("this is the finalizer.");}}

Class capplication {public static void main () {console.writeline ("this is main."); ctest test = new ctest (); // gc.requestfinalizeonseonShutdown ();}} Run this program, then remove GC.RequestFinalizeonShutdown () This line of comments marked and re-run, pay attention to what is different ...

5.8 How do I know what the garbage collector is doing? Many of the .NET Runturing Base is output through the 'COM MEMORY' performance object. Use the Performance Monitor to view them.

6. Attribute 6.1 What is the property? There are minimal type .NET properties. The first category I call it Metadata property - it allows some data to be attached to the class or method. These data are numbered as part of the Metadata, and can be accessed by mapping like other Metadata classes. Another property of Metadata is [Serializable], which is attached to the class, indicating that the instance of the class can be serialized.

[Serializable] Public class ctest {} Another type of attribute is context properties. The properties of the context type use and Metadata similar syntax, but they are actually different. The context type attribute provides an interpretation mechanism that can be pre-processed and / or subsequently processed by this mechanism. If you know the General Brown's General Brown, you might be familiar with this idea.

6.2 Can I create my own metadata properties? Yes it is. Simply export a class from System.attribute and tag it as an AttributeUSAGE property. For example: [AttributeUSAGETS.CLASS] PUBLIC CLASS INSPIREDBYATTRIBUTE: system.attribute {public string inspiredby

Public InspiredByattribute (String Inspiredby) {INSPIREDBY = Inspiredby;}}

[InspiredBy ( "Andy Mc's brilliant .NET FAQ")] class CTest {} class CApp {public static void Main () {object [] atts = typeof (CTest) .GetCustomAttributes (); foreach (object att in atts) if ( ATT IS ISPIREDBYATTRIBUTE) Console.writeline ("Class Ctest Was Inspired By {0}", _ (InspiredByattribute); {}}

6.3 Can I create my own context attribute? Yes it is. Take a look at the TRATER DRAYTON at the Don Box at http://www.develop.com/dbox/dotnet/threshold (called Callthreshold) and http://www.razorsoft.net/ TRATER DRAYTON TRACEHOK.NET

7. Code Access Security 7.1 What is Code Access Security (CAS)? CAS is part of the .NET security model, which determines if a code is allowed to be run, and what resources can be used when it runs. For example, CAS can prevent a .NET's web applet to format your hard drive.

7.2 How does Cas work? CAS Security Policy Design Two Key Concepts - Code Groups and Permissions. Each .NET component is a member of a particular code group, and each code group is granted by the permissions specified by the listing set.

For example, when using the default security policy, a control downloaded from the Web site belongs to the "Zone - Internet" code group that keeps the permissions defined by the "Internet" by the Amissive Right Set Set. (Nature, the name "Internet" indicates a group of privileges that are strictly limited.)

7.3 Who defines the CAS code group? Microsoft defines some default code groups, but you can change these even created your own code group. To see the code group defined in your system, you can run the "Caspol -l" command from the command. I look like these in my system:

Level = Machine

Code Groups:

1. All code: Nothing 1.1 Zone - MyComputer:.. FullTrust 1.1.1 Honor SkipVerification requests: SkipVerification 1.2 Zone - Intranet:. LocalIntranet 1.3 Zone - Internet:. Internet 1.4 Zone - Untrusted:.. Nothing 1.5 Zone - Trusted: Internet 1.6 StrongName - 0024000004800000940000000602000000240000525341310004000003000000CFCB3291AA715FE99D40D49040336F9056D7886FED46775BC7BB5430BA4444FEF8348EBD06F962F39776AE4DC3B7B04A7FE6F49F25F740423EBF2C0B89698D8D08AC48D69CED0FC8F83B465E0807AC11EC1DCC7D054E807A43336DDE408A5393A48556123272CEEEE72F1660B71927D38561AABF5CAC1DF1734633C602F8F2D5:. Everything note code group hierarchy - top ( 'All code') is the most common, which is subsequently divided into several groups, each of which can also be subdivided. At the same time, the subgroups can be given a wider permission set than its superiors. 7.4 How to define your own code group? Use Caspol. For example, assume you trust the code from www.mydomain.com, and hope that it has full access to your system, but you want to maintain the default restrictions on other Internet sites. To achieve this, you can add a subgroup in the "Zone - Internet" group, just like the following:

Caspol -ag 1.3 -site www.mydomain.com FullTrust now If you run caspol -lg, you can see the new code group is added to 1.3.1 Group:

... 1.3. Zone - Internet: Internet 1.3.1. Site - www.mydomain.com: FullTrust ... Note Number Number (1.3.1) is just Caspol to be easily manipulated from the command line. The bottom of the running library will never see it.

7.5 How to change the authority set of code group? Use Caspol. If you are a machine administrator, you can operate at 'Machine' Hierarchy - Not only means that you do will become the default setting of the machine, but the user cannot reform more widely. If you are an ordinary user (not an administrator) you can still modify the permissions, but you can only make them strict. For example, in order to make the intranet code to do what they want, you may need this:

Caspol -cg 1.2 FullTrust pays attention, because (in standard systems) This is larger than the default security policy permissions, you should do this at the Machine level - do not work in this User hierarchy.

7.6 Can I create my own permissions? Yes it is. Use caspol -ap to specify an XML file that contains all permissions in the permissions set. Here is an example file specified by 'everything' permission set - modify it to adapt to your needs, so you can save some time. After the modification is complete, use the following method to add it to the available permissions:

CASPOL -AP SAMPLEPERMSET.XML and then applies this permission set to a code group with the following method: Caspol -cg 1.3 Samplepermset (By default, 1.3 is the 'Internet' code group)

7.7 How do you diagnose your own procedure when there is a problem? Caspol has a group of possible options. First, use Caspol -RSG, you can let Caspol tell you which code group belongs to. Similarly, using Caspol -RSP, you can ask what permissions applied on a particular component.

7.8 I can't stand the trouble brought by CAS, can I turn off it? Yes, as long as you are a system administrator. Just run:

Caspol -s off

8. Intermediate Language (IL) 8.1 Can I see the middle language of the component? Yes it is. Microsoft provides a tool called ILDASM that can be used to view metadata and IL of the components.

8.2 Can I get the source code from IL by reverse engineering? Yes it is. Relatively, from IL to regenerate advanced language source code (e.g., C #) is usually very simple.

8.3 How to prevent someone from get my code through the reverse engineering? The only way to run is an ILASM with / owner option. The IL of the component generated can not be viewed through ILDASM. However, the deterministic code of the unconventional code can crack the ILDASM or write its own ILDASM version, so this method can only scare the burst of amateurns.

Unfortunate things, current .NET compilers do not / owner options, so want to protect your C # or VB.NET components, you need to do it below:

CSC helloworld.csildasm /out=temp.il helloworld.exeilasm / Owner Temp.il (This suggestion is Hany Ramadan to Dotnet.)

It seems that there is an IL encryption tool for a while (regardless of the Microsoft or third party). These tools will "optimize" IL in such a way that the reverse project has become more difficult.

Of course, if you are writing a web service, the reverse project is no longer a problem, because the customer cannot access your IL.

8.4 Can I use IL to program directly? Yes it is. Peter Drayton posted this simple example in the DOTNET mailing list:

.assembly myassembly {} .class myApp {.method static void main () {.entrypoint ldstr "Hello, IL!" call void system.console :: write}} Put it in name Hello In the .il's file, then run ILASM Hello.il, an EXE element will be generated.

8.5 IL can do something you can't do in C #? Yes it is. Some simple examples are: You can throw an exception exported from systemException, and you can use an array of non-zero start.

9. Did it done about COM9.1 COM? Just as you can see in the mailing list, this topic leads to a fierce debate. Take a look at the following two places:

http://discuss.develop.com/archives/wa.exe?a2=ind0007&l=dotNet&d=0&p=68241 http://discuss.develop.com/archives/wa.exe?a2=ind0007&l=dotNet&p=r60761 My It is understood that COM contains a lot of content, and it is different for different people. But for me, COM is basically about how a small code is found to find another small code, and how to communicate with each other after they find each other. COM accurately indicates how this positioning and communication is going. In the "pure" .NET world consisting entirely of .NET objects, the small code is still looking for each other and talks with each other, but they don't use COM. They use a model that is very similar in certain places and COM - for example, type information saved in and component encapsulated together, which is very similar to the package in COM components. But it is not COM.

So, is there any problem? Ok, I don't care about most COM disappeared - I don't care about the component is no longer related to the registry, I don't use IDL to define my excuse. But there is something I don't want it to disappear - I don't want to lose this idea based on the interface-based development. According to my opinion, COM's most powerful power is it insisted on erecting iron wall between interfaces and implementations. Unfortunately, it seems that .NET is no longer in that - it allows you to do an interface-based development, but it doesn't stick to it. Some people may argue that there is always a bad thing, maybe they are right, but I can't think that this may be a retreat.

Did the DCOM died? Almost, especially for .NET developers. The .NET frame has a new remote model that is not DCOM. Of course, DCOM will also be used in interoperability.

9.3 MTS / COM done? Do not. The first .NET version considers the provision of existing COM services (via an interoperability layer) instead of using .NET's own services to replace them. Many tools and properties are used to achieve as smooth transition as possible. The PDC version of .NET SDK includes support for core services (JIT activities, transactions), but excludes some high-level services (such as COM events, queue components).

In a period of time, interoperability can be expected to be seamless integration - this means that some services will become part of the CLR, and / or means that some services will be override and run in CLR in the form of manageable code. Top floor.

For this topic, see Joe Long's Post-Joe is the manager of Microsoft's COM group. From here:

Http://discus.develop.com/archives/wa.exe?a2=ind0007&l=dotNet&p=r68370

9.4 Can I use COM components in .NET? can. You can access the COM components from the .NET via the Runtime Callable Wrapper (RCW). It allows the COM interface to be accessed by mapping COM components to interfaces with .NET compatible interfaces. For the OldAutomation interface, you can automatically generate from a type library. For non-OleAutomation interfaces, a custom RCW can be developed to manually map the type of COM interface to the type with .NET compatible.

For readers who are familiar with ATL, there is a simple example. First, create an ATL component to implement the following IDL:

Import "OAIDL.IDL"; import "ocidl.idl";

[Object, uuid (EA013F93-487A-4403-86EC-FD9FEE5E6206), helpstring ( "ICppName Interface"), pointer_default (unique), oleautomation] interface ICppName: IUnknown {[helpstring ( "method SetName")] HRESULT SetName ([in ] Bstr name); [Helpstring ("Method getName"] HRESULT GETNAME ([OUT, RETVAL] BSTR * PNAME);

[Uuid ​​(F5E4C61D-D93A-4295-A4B4-2453D4A4484D), version (1.0), helpstring ( "cppcomserver 1.0 Type Library")] library CPPCOMSERVERLib {importlib ( "stdole32.tlb"); importlib ( "stdole2.tlb"); [UUID (600CE6D9-5ED7-4B4D-BB49-E8D5D5096F70), Helpstring ("CPPName Class")] CoClass cppname {[default] interface icpname;};}; after the component is established, you will get a TypeLibrary. Run the TLBIMP utility on TypeLibrary, just like this:

Tlbimp cppcomserver.tlb If you succeed, you will get information like this:

Typelib Imported successfully to cppcomserverlib.dll Now you need a .NET client - we create a .cs file containing the following code with C #:

Using system; using cppcomserverlib;

Public class mainapp {static public void main () {cppname cppname = new cppname (); cppname.setname ("bob"); console.writeline ("name is" cppname.getname ());}} Note We use Typelibrary The name as a namespace, the name of the COM class as class name. We can also choose to use cppcomserverlib.cppname as class names and do not need statements for CPPCOMSERVERLIB.

Compiled with C # code like this:

CSC /R: cppcomserverlib.dll csharpcomclient.cs Note that compiling is notified, quote We just generated from TLBIMP from TypeLibrary.

Now you should be able to run csharpcomclient.exe, and get the following output from the console:

Name is bob

9.5 Can you use the .NET component in COM? can. The .NET component can be accessed from the COM via a COM CALLABLE WRAPER (CCW). This is similar to RCW (see the previous issue), but work in the opposite direction. Similarly, if it cannot be automatically generated by .NET development tool, or do not want to automatically generate behavior logic, you can develop a custom CCW. To enable COM to "see" .NET components, .NET components must be registered in the registry. Here is a simple example. Create a C # file called TestComServer.cs and enter the following code:

Using system;

namespace AndyMc {public class CSharpCOMServer {public CSharpCOMServer () {} public void SetName (string name) {m_name = name;} public string GetName () {return m_name;} private string m_name;}} then compiled .cs file:

CSC / Target: library testcomserver.cs You will get a DLL, so register it:

RegaSM testcomserver.dll /tlb:TestComServer.tlb now you need to create a client program to test your .NET COM component. VBScript can - put the following in a file called Comclient.vbs:

DotNetobj Set DotNetobj = CreateObject ("Andymc.csharpcomServer) DotNetobj.setName (" Bob ") msgbox" name is "& dotNetobj.getname () Run this script:

WScript Comclient.vbs Hey! You get a message box that displays text "name is bob".

(Note, when writing this program, it seems to be accessed by several paths as COM components - To avoid problems, run Comclient.vbs in the same directory in TestComServer.dll.

An alternative method is DM.NET Moniker developed using Jason Whittington and Don Box. Here http://staff.develop.com/jasonw/clr/readme.htm view.

9.6 Is ATL in the world of .NET? Yes it is. If you are writing the application within the .NET framework. Of course, many developers want to continue to use ATL to write C COM components other than the .NET framework, but when you are in the .NET framework, you always want to use C #. In the .NET world, the original C (and its ATL) did not have too many status - it is too straightforward and provides too much adaptability, so that the runtime cannot manage it.

10. How does the remote calculation of. NET? The remote computing of .NET involves sending messages through the channel. Two standard channels are HTTP and TCP. Only in LANs tend to use TCP-HTTP to be used on the LAN and WAN (Internet).

Support for multiple messaging formats now provides, such as SOAP (based on XML) and binary formats. By default, the HTTP channel uses SOAP (Serialization SOAP Formatter through the .NET Runture), while the TCP channel uses a binary format (Serialization Binary Formatter through the .NET Runture). But each channel can be used in any serialization format. Here is some ways to access remote access:

SingleCall. Each request from the client is served by a new object. When the request is completed, the object is discarded. You can use ASP country services in the ASP environment to save applications or sessions, making this model (no country's division) becomes national support. Singleton. All requests to clients are processed by a single server object. Client-activated object. This is the old country support (D) COM model, where the client is received by a remote object and retains this reference (to maintain the remote object's survival) until it is completed. The distributed garbage collection of objects is managed by the "Based on Rent Lifecycle". Each object has a rental time, which is disconnected from the .NET running library when arriving at this time. Objects have default update time - the successful call initiated from the client will update the rental time. The client can also update the rental time.

If you use XML-RPC instead of SOAP, you can see Charles Cook at http://www.cookcomputing.com/xmlrpc/xmlrpc.shtml XML-RPC.NET site.

10.2 How to get Win32 API in .NET? Use P / Invoke. It uses technologies similar to COM interoperability, but is used to access static DLL entry points instead of COM objects. The following is an example of a C # program called a Win32 MessageBox function:

Using system; using system.runtime.interopservices;

class MainApp {[dllimport ( "user32.dll", EntryPoint = "MessageBox", SetLastError = true, CharSet = CharSet.Auto)] public static extern int MessageBox (int hWnd, String strMessage, String strCaption, uint uiType);

Public static void main () {MessageBox (0, "Hello, This Is Pinvoke In Operation!", ".NET", 0);}}

11. Class library 11.1 file I / O11.1.1 How to read text files? First, open the file using the System.IO.FileStream object:

FILESTREAM FS = New FileStream (@ "c: /test.txt", filemode.open, fileaccess.read; fileStream inherits to Stream, so you can pack the FileStream object with a StreamReader object. This provides a good interface for a row of rows:

StreamReader SR = New StreamReader (FS); String curline; while ((curline = sr.readline ())! = Null); finally closed StreamReader object: sr.close (); note this will automatically CLOSE () is called on the underlying Stream object, so it is not necessary to perform fs.close ().

11.1.2 How to write a text file? Similar to the example of reading the file, just replace StreamReader to streamwriter.

11.1.3 How to read a binary? Similar to text files, just use binaryreader / write objects instead of streamreader / write to pack the filestream object.

11.1.4 How to delete a file? Use the static method to use the static method delete (): in System.IO.FILE object ():

File.delete (@ "c: /test.txt");

11.2 Text Process 11.2.1 Does the regular expression are supported? Yes it is. Use the System.Text.RegularExpressions.Regex class. For example, the following code updates the title of the HTML file:

FileStream Fs = New FileStream ("Test.htm", FileMode.Open, FileAccess.Read; StreamReader SR = New StreamReader (FS);

Regex r = new regex (" (. *) </ Title>"); string s; while ((s = sr.readline ())! = Null) {if (R.ismatch (s)) s = R.Replace (s, "<title> new and improved $ {1} </ title>"); console.writeline (s);}</p> <p>11.3 Internet11.3.1 How to download the web? First use the System.Net.WebRequestFactory class to get a WebRequest object:</p> <p>WebRequest Request = WebRequestFactory.create ("http: // localhost"); then request a response:</p> <p>WebResponse response = Request.getResponse (); getResponse method is blocked until the download is complete. Then you can access your response as you:</p> <p>Stream s = response.getResponseSstream ();</p> <p>// Output the downloaded stream to the consoleStreamReader sr = new StreamReader (s); string line; while ((line = sr.ReadLine ()) = null!) Console.WriteLine (line); Note WebReponse WebRequest objects and downwardly, respectively, Compatible with HTTPWebRequest and HttpWebReponse objects, they are used to access and HTTP-related features.</p> <p>11.3.2 How to use proxy servers (Proxy)? Two kinds - do in order to affect all WEB requests:</p> <p>System.Net.GlobalProxySelection.Select = new DefaultControlObject ( "proxyname", 80); another, in order to request a particular set of the Web proxy service, to do so: ProxyData proxyData = new ProxyData (); proxyData.HostName = "proxyname "; proxydata.port = 80; proxyData.overridelectProxy = true;</p> <p>HTTPWebrequest Request = (httpwebrequest) WebRequestFactory.create ("http: // localhost"); request.proxy = proxydata;</p> <p>11.4 XML11.4.1 Does DOM? Yes it is. Take a look at the following example XML document:</p> <p><People> <persons> Fred </ person> <person> Bill </ person> </ people> can handle this document this:</p> <p>XMLDocument doc = new xmldocument (); doc.load ("test.xml");</p> <p>XMLNode root = doc.documentelement;</p> <p>"Xmlnode PersonElement in root.childnodes) console.writeline (PersonElement.firstchild.Value.toString ()); output is:</p> <p>Fredbill</p> <p>11.4.2 Do you support SAX? Do not. As a replacement, a new XMLReader / XMLWRITER API is provided. Like SAX, it is streaming, but it uses the "PULL" model rather than the "Push" model of SAX. This is an example:</p> <p>XMLTextReader Reader = New XMLTextReader ("Test.xml");</p> <p>While (Reader.Read ()) {if (reader.NodeType == xmlnodetype.eray == xmlnodetype.element && reader.name == "Person") {reader.read (); // skip to the child text console.writeline (Reader.Value }}</p> <p>11.4.3 Do you support xpath? Yes, through the XMLnavigator class (Documentnavigator is exported from xmlnavigator):</p> <p>XMLDocument doc = new xmldocument (); doc.load ("test.xml");</p> <p>Documentnavigator nav = new documentnavigator (doc); nav.movetodocument ();</p> <p>Nav.Select ("Descendant :: People / Person);</p> <p>While (nav.movetonextSelected ()) {nav.movetofirstchild (); console.writeline ("{0}", nav.value);</p> <p>11.5 Thread 11.5.1 Do you support multithreading? Yes, there is a wide range of support for multithreading. The system can generate a new thread and provide a thread pool that the application can use. 11.5.2 How to generate a thread? Create an instance of the System.Threading.Thread object to pass the ThreadStart sample that will be executed in the new thread to it. E.g:</p> <p>Class mythread {public mythread (string initdata) {m_data = initdata; m_thread = new thread (new threadstart (threadmain)); m_thread.start ();</p> <p>// threadmain () is executed on the new thread. Private void threadmain () {console.writeline (m_data);</p> <p>Public void waituntilfinished () {m_thread.join ();</p> <p>Private thread m_thread; private string m_data;} An instance of creating Mythread is enough to generate a thread and execute mythread.threadmain () method:</p> <p>Mythread T = New Mythread ("Hello, World."); T.waituntilfinished ();</p> <p>11.5.3 How to stop a thread? There are several ways. First, you can use your own communication mechanism to tell the threadstart method to end. In addition, the Thread class has built-in support to command the thread to stop. Basic two methods are Thread.Interrupt () and thread.abort (). The former caused a ThreadInterruptedException and then entered the WaitJointEP state. In other words, Thread.Interrupt is a polite way that requests the thread to stop when there is no useful work. Corresponding to this, thread.abort () throws a ThreadAbortexception instead of the consignment of the thread. Moreover, ThreadAbortException cannot be captured as usual (even if the THReadStart termination) is performed. Thread.abort () is a very means of unnecessary under normal circumstances.</p> <p>11.5.4 How to use a thread pool? Pass WaitCallback from the ThreadPool.QueueUserWorkItem () method:</p> <p>Class capp {static void main () {string s = "Hello, World"; threadpool.queueuserWorkItem (New Waitcallback (DOWORK), S)</p> <p>Thread.sleep (1000); // Give Time for Work Item to Be Execute}</p> <p>// DOWORK IS EXECUTED ON A Thread from the thread pool. Static void DOWORK (Object State) {Console.writeline (state);}}</p> <p>11.5.5 How do I know when my thread pool work project is completed? There is no way to ask the thread pool such information. You must place the code in the waitCallback method to issue a signal to indicate that it has been completed. The event here is also useful. 11.5.6 How to prevent concurrent access to the data? Each object has a unlocked and unlocked part of the criticism. System.Threading.monitor.Enter / Exit method is used to get and release the lock. For example, the following examples only allow one thread to simultaneously enter the method f ():</p> <p>Class C {public void f () {monitor.Enter (this); ...} finally {monitor.exit (this);}}} C # has a keyword 'lock' provides simple forms of the above code:</p> <p>Class C {public void f () {lock (this) {...}}} Note that calls Monitor.Enter (myObject) does not mean that all access to myObject is serially connected. It means the synchronization lock that is associated with myObject and no other thread can request the lock before calling Monitor.exit (o). In other words, the classes given below are equivalent:</p> <p>Class C {public void f () {lock (m_object) {...}}</p> <p>PRIVATE M_Object = New Object ();</p> <p>11.6 Tracking 11.6.1 Is there a built-in tracking / log support? Yes, in the system.diagnostics namespace. There are two main classes for processing tracks - Debug and Trace. They work in a similar manner-different is that the tracking in the Debug class can only work in the code generated by the Debug flag, and the tracking in the Trace class can only work in the code generated by the Trace tag. Typically, this means you should use System.Diagnostics.Trace.writeline when you want to track in debug and release versions, and use system.diagnostics.debug when you want to track it in the debug version. .Writeline.</p> <p>11.6.2 Can I redirect the tracking output to a file? Yes it is. Both the Debug class and the Trace class have a listners attribute, which collects the output you generated by Debug.Writeline or Trace.writeline. By default, only one collection slot is an instance of the DEFAULTTRACELISTENER class. It sends output to Win32 OutputDebugString () function and system.diagnostics.debugger.log () method. This is useful when debugging, but if you try to track a problem from the customer site, it is more appropriate to redirect the output to a file. Fortunately, the TEXTWRITERTRACELISTENER class is provided for this purpose.</p> <p>Here is how TextWritertracelistener is redirected to a file:</p> <p>Trace.Listeners.clear (); FileStream Fs = New FileStream (@ "c: /log.txt", filemode.create, fileaccess.write; trace.listeners.add (new textwritertracelistener (fs)); trace.writeline @ "This will be writen to c: /log.txt!"); Note Use trace.listener.clear () remove the default Listener. If not do it, the output will be generated simultaneously in the file and OutputDebugString (). Under normal circumstances, you don't want this, because OutputDebugString () leads to great performance overhead.</p> <p>11.6.3 Can you customize the output of tracking? Yes it is. You can write your own tracelistener export class and redirect all output to it. Here is a simple example, it exports from the TextWritrtracelistener (and then built support for write files) and add time information and thread ID on each output line:</p> <p>Class MyListener: TextWritertracelistener {Public MyListener (stream s): base (s) {}</p> <p>Public override void writeline ("{0: D8} [{1: D4}] {2}", Environment.TickCount - m_starttickcount, appdomain.getCurrentThreadId (), s);}</p> <p>Protected int m_starttickcount = environment.tickcount;} (Note this implementation is not complete -, for example, the tracelistener.write method is overwritten.)</p> <p>The beauty of this method is that after adding MyListener to Trace.Listener, all TRACE.WRITELINE () turned to MyListener, including the call from the reference element that is not known to myListener.</p> <p>12. Resources 12.1 Where can I get details about .NET? The Microsoft .NET homepage is http://www.microsoft.com/net/. Microsoft also releases it in GotdotNet.</p> <p>Microsoft also released .NET Framework FAQ, and this article very similar. You can find a lot of questions more "authoritative".</p> <p>Robert Scoble edited a very easy to understand online list http://www.devx.com/dotnet/Resources/, there is also a http://www.singularidad.com.ar/dotnet.asp.</p> <p>At http://www.devx.com/free/press/2000/vs-qalist.asp Robert also has a .NET "Famous Issues & Solution" home page.</p> <p>Richard GRIMES and Richard Anderson have a site called Managed World.com.</p> <p>http://www.ibuyspy.com/ is an example site created with a destination .NET platform.</p> <p>There is also my C # FAQ for C Programmers.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-130780.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="130780" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.048</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'ROs85aImrQdaTh97v3f5sxjklNOIJoyWJv43uKFOgBgCYTZAA69_2FmJS7cCrOU52jsHUp8mfwos0pZBhyR4q_2FsA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>