Debugging: Walkthrough: Debugging a Multithreaded Application

http://msdn.microsoft.com/en-us/library/bb157784.aspx#Y1056 // Walkthrough: Debugging a Multithreaded Application

http://msdn.microsoft.com/en-us/library/ts553s52.aspx // Creating Threads and Passing Data at Start Time

Walkthrough: Debugging a Multithreaded Application

Visual Studio 2010 provides an improved Threads window and other user interface improvements to make it easier to debug multithreaded applications. This walkthrough takes only a few minutes, but completing it will familiarize you with the new interface features for debugging multithreaded applications.

To begin this walkthrough, you need a multithreaded application project. Follow the steps listed here to create that project.

To create the walkthrough project

1. On the File menu, choose New and then click Project.

The New Project dialog box appears.

2. In the Project Types box, click the language of your choice: Visual Basic, Visual C#, or Visual C++.

3. In the Templates box, choose Console Application or CLR Console Application.

4. In the Name box, type the name MyThreadWalkthroughApp.

5. Click OK.

A new console project appears. When the project has been created, a source file appears. Depending on the language you have chosen, the source file might be called Module1.vb, Program.cs, or MyThreadWalkthroughApp.cpp

6. Delete the code that appears in the source file and replace it with the example code that appears in the section "Creating a Thread" of the topic Creating Threads and Passing Data at Start Time.

7. On the File menu, click Save All.

To begin the walkthrough

· In the source window, look for the following code:

VB

C#

C++

F#

JScript

Copy

No code example is currently available or this language may not be supported.

VB

C#

C++

F#

JScript

Copy

Thread.Sleep(3000);

Console.WriteLine();

To start debugging

1. Right-click the Console.WriteLine statement, point to Breakpoint and then click Insert Breakpoint.

In the gutter on the left side of the source window, a red ball appears. This indicates that a breakpoint is now set at this location.

2. On the Debug menu, click Start Debugging.

Debugging starts, your console application starts to run, and then stops at the breakpoint.

3. If the console application window has focus at this point, click in the Visual Studio window to return focus to Visual Studio.

4. In the source window, locate the line that contains the following code:

VB

C#

C++

F#

JScript

Copy

No code example is currently available or this language may not be supported.

VB

C#

C++

F#

JScript

Copy

Thread.Sleep(3000);

1.

To discover the thread marker

1. Right-click in the Threads window, then click Show Threads in Source.

2. Look at the gutter on the left side of the window. On this line, you will see an icon that resembles two cloth threads. One thread is red and the other is blue. The thread marker indicates that a thread is stopped at this location. Possibly, thread is stopped at this location.

3. Hover the pointer over the thread marker. A DataTip that appears. The DataTip tells you the name and thread ID number for each stopped thread. In this case, there is only one thread, whose name is probably <noname>.

4. Right-click the thread marker. Note the choices on the shortcut menu.

This icon is a thread marker:

Flagging and Unflagging Threads

Advertisements

SQL: How to enable SSL encryption for an instance of SQL Server by using Microsoft Management Console

http://support.microsoft.com/kb/316898

How to enable SSL encryption for an instance of SQL Server by using Microsoft Management Console

This step-by-step article describes how to install a certificate on a computer that is running Microsoft SQL Server 2000 or Microsoft SQL Server 2005 by using Microsoft Management Console (MMC) and describes how to enable SSL Encryption at the server, or for specific clients.

Note You cannot use this method to put a certificate on a SQL Server clustered server.

If your company has implemented an Enterprise Certificate Authority, you can request certificates for a SQL Server stand-alone server, and then use the certificate for Secure Sockets Layer (SSL) encryption.

You can enable the Force Protocol Encryption option on the server, or on the client.

Note Do not enable the Force Protocol Encryption option on both the client and the server. To enable Force Protocol Encryption on the server, use the Server Network Utility. To enable Force Protocol Encryption on the client, use the Client Network Utility.

Important If you enable SSL encryption by using the Client Network Utility, then all connections from that client will request SSL encryption to any SQL Server to which that client connects.

Warning If you enable Force Protocol Encryption on the client computer, you cannot connect to previous versions of SQL Server from that specific client. Previous versions of SQL Server do not recognize SSL encryption.

If you enable Force Protocol Encryption on the server, you must install a certificate on the server.

If you want to enable Force Protocol Encryption on the client, you must have a certificate on the server and the client must have the Trusted Root Authority updated to trust the server certificate.

Note If you are using SQL Server 2005 to enable encrypted connections for an instance of SQL Server 2005, you can set the value of the ForceEncryption option to Yes. For more information, see the "How to: Enable Encryption Connections to the Database Engine (SQL Server Configuration Manager)" topic in SQL Server 2005.

Back to the top

Install a certificate on a server with Microsoft Management Console (MMC)

To use SSL encryption, you must install a certificate on the server. Follow these steps to install the certificate by using the Microsoft Management Console (MMC) snap-in.

How to Configure the MMC Snap-in

1. To open the Certificates snap-in, follow these steps:

a. To open the MMC console, click Start, and then click Run. In the Run dialog box type:

MMC

b. On the Console menu, click Add/Remove Snap-in….

c. Click Add, and then click Certificates. Click Add again.

d. You are prompted to open the snap-in for the current user account, the service account, or for the computer account. Select the Computer Account.

e. Select Local computer, and then click Finish.

f. Click Close in the Add Standalone Snap-in dialog box.

g. Click OK in the Add/Remove Snap-in dialog box. Your installed certificates are located in the Certificates folder in the Personal container.

2. Use the MMC snap-in to install the certificate on the server:

. Click to select the Personal folder in the left-hand pane.

a. Right-click in the right-hand pane, point to All Tasks, and then click Request New Certificate….

b. The Certificate Request Wizard dialog box opens. Click Next. Select Certificate type is "computer".

c. In the Friendly Name text box you can type a friendly name for the certificate or leave the text box blank, and then complete the wizard. After the wizard finishes, you will see the certificate in the folder with the fully qualified computer domain name.

d. If you want to enable encryption for a specific client or clients, skip this step and proceed to the Enable encryption for a specific client section of this article.

If you want to enable encryption at the server, open the Server Network Utility on the server where the certificate is installed, and then click to select the Force protocol encryption check box. Restart the MSSQLServer (SQL Server) service for the encryption to take effect. Your server is now ready to use SSL encryption.

Back to the top

Enable encryption for a specific client

For the client to request the SSL encryption, the client computer must trust the server certificate and the certificate must already exist on the server. You have to use the MMC snap-in to export the Trusted Root Certification Authority used by the server certificate:

1. To export the server certificate’s Trusted Root Certificate Authority (CA), follow these steps:

a. Open MMC, and then locate your certificate in the Personal folder.

b. Right-click the certificate name, and then click Open.

c. Review the Certification Path tab. Note the top most item.

d. Navigate to the Trusted Root Certification Authorities folder, and then locate the Certificate Authority noted in step c..

e. Right-click CA, point to All Tasks, and then click Export.

f. Select all the defaults, and then save the exported file to your disk where the client computer can access the file.

2. Follow these steps to import the certificate on the client computer:

. Navigate to the client computer by using the MMC snap-in, and then browse to the Trusted Root Certification Authorities folder.

a. Right-click the Trusted Root Certification Authorities folder, point to All Tasks, and then click Import.

b. Browse, and then select the certificate (.cer file) that you generated in step 1. Select the defaults to complete the remaining part of the wizard.

c. Use the SQL Server Client Network Utility.

d. Click to select the Force Protocol encryption option. Your client is now ready to use SSL encryption.

Back to the top

How to test your client connection

To test your client connection you can either:

  • Use the Query Analyzer Tool.

    -or-

  • Use any ODBC application where you can change the connection string.

Query Analyzer Tool

To use the Query Analyzer Tool, follow these steps:

1. Use the SQL Server Client Network Utility.

2. Click to select the Force protocol encryption option.

3. Connect to the server that is running SQL Server 2000 by using Query Analyzer.

4. Monitor the communication by using Microsoft Network Monitor or a Network Sniffer.

ODBC or OLEDB Application Sample Connection Strings

If you use ODBC or OLEDB connection strings, follow these steps:

1. Modify the ODBC or OLEDB connection string. For example:

ODBC

Driver=SQLServer;Server=ServerNameHere;UID=UserIdHere;PWD=PasswordHere;Network=DBNETLIB.DLL;Encrypt=YES

OLEDB

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbNameHere;Data Source=ServerNameHere;Use Encryption for Data=True

2. Connect to the server that is running SQL Server 2000, and then monitor the communication by using Microsoft Network Monitor or a Network Sniffer.

Back to the top

Troubleshooting

After you successfully install the certificate, the certificate does not appear in the Certificate list on the Certificate tab.

Note The Certificate tab is in the Protocols for <InstanceName> Properties dialog box that is opened from SQL Server Configuration Manager.

This issue occurs because you may have installed an invalid certificate. If the certificate is invalid, it will not be listed on the Certificate tab. To determine whether the certificate that you installed is valid, follow these steps:

1. Open the Certificates snap-in. To do this, see step 1 in the "How to Configure the MMC Snap-in" section.

2. In the Certificates snap-in, expand Personal, and then expand Certificates.

3. In the right pane, locate the certificate that you installed.

4. Determine whether the certificate meets the following requirements:

o In the right pane, the value in the Intended Purpose column for this certificate must be Server Authentication.

o In the right pane, the value in the Issued To column must be the server name.

5. Double-click the certificate, and then determine whether the certificate meets the following requirements:

o On the General tab, you receive the following message:

You have a private key that corresponds to this certificate.

o On the Details tab, the value for the Subject field must be server name.

o The value for the Enhanced Key Usage field must be Server Authentication (<number>).

o On the Certification Path tab, the server name must appear under Certification path.

If any one of these requirements is not met, the certificate is invalid.

Install Certificate Services on Windows Server 2008 R2

http://d3planet.com/rtfb/2009/11/10/install-certificate-services-on-windows-server-2008-r2/

Install Certificate Services on Windows Server 2008 R2

By Clement DeLarge on November 10th, 2009

This post picks up where the last post left off. In the last post, we created a Windows Server 2008 R2 Active Directory Domain Controller and stopped short of going on to add Certificate Services into the mix.

If you’re not sure if you need certificate services for your environment, it never hurts to have it available. It does not add much overhead so for development environments and small businesses you can consider adding the role to a DC (domain controller) as we are here. Certificate Services will allow you to issue certificates to your internal resources, use client/server certificates for authentication, and set up SSL enabled websites.

I believe best practice is, and I’m sure someone will correct me if I’m wrong, to set up an Enterprise Root CA (Certificate Authority), then set up one or more subordinate CA’s. You can then make your Root CA unavailable for access and have the subordinates handle all of the traffic without fear of compromising your Root CA. In this tutorial, we’ll just be installing and configuring a Root CA, but the process is basically the same for the subordinates.

Now that you’ve got some background information, onto the installation/configuration of Windows Server 2008 R2 Certificate Services.

In ‘Server Manager’, select Roles in the left pane, then Add Roles in the right pane. Place a check mark in the checkbox for Active Directory Certificate Services. Then click Next.

Keep reading…

On the ‘Introduction to Active Directory Certificate Services’ window, you can read up on the certificate services technology, how to manage a CA, and naming. Click Next.

On the ‘Select Role Services’ page, make sure Certification Authority is selected, then select Certification Authority Web Enrollment, when the ‘Add Roles Wizard’ window appears click the Add Required Role Services button. Click Next.

On the ‘Specify Setup Type’ page, leave Enterprise selected. Click Next. On the ‘Specify CA Type’ page, leave Root CA selected and click Next. On the ‘Set Up Private Key’ page, leave Create a new private key selected and click Next.

On the Configure Cryptography for CA page, you can leave the defaults selected or adjust as necessary for your needs. You can also pause here and research the providers and hashes as necessary, but for this tutorial and most environments, the default will suffice. Click Next.

On the ‘Configure CA Name’ page, set the common name to the same as the server name since this server is a domain controller. This is an acceptable practice. Leave the ‘Distinguished name suffix’ alone. Click Next.

On the ‘Set Validity Period’ page, feel free to adjust the validity period or leave the default. This should be adjusted based on your needs. Click Next. On the ‘Configure Certificate Database’ page, you can adjust the paths or leave the defaults set. Click Next.

Next we see the ‘Web Server (IIS)’ page. You can read the description and check out the links listed on the page if you’d like. Click Next.

On the ‘Select Role Services’ page, leave the defaults selected. Click Next. On the ‘Confirm Installation Selections’ page, you can review your choices, go back and make changes, or click Install. After the ‘Installation Progress’ page finishes, you can view your ‘Results’.

You’ve now got a domain controller that is capable of issuing certificates to your servers and users. You can go back through the wizard and install additional CA components, for example, that will allow you to issue certificates to users and computers that are not part of your domain. That option is called ‘Certificate Enrollment Web Service’.

Anonymous Methods (C# Programming Guide)

http://msdn.microsoft.com/en-us/library/0yw3tz5k.aspx

Anonymous Methods (C# Programming Guide)

Visual Studio 2010

Other Versions

·Visual Studio 2008

·Visual Studio 2005

In versions of C# before 2.0, the only way to declare a delegate was to use named methods. C# 2.0 introduced anonymous methods and in C# 3.0 and later, lambda expressions supersede anonymous methods as the preferred way to write inline code. However, the information about anonymous methods in this topic also applies to lambda expressions. There is one case in which an anonymous method provides functionality not found in lambda expressions. Anonymous methods enable you to omit the parameter list. This means that an anonymous method can be converted to delegates with a variety of signatures. This is not possible with lambda expressions. For more information specifically about lambda expressions, see Lambda Expressions (C# Programming Guide).

Creating anonymous methods is essentially a way to pass a code block as a delegate parameter. Here are two examples:

VB

C#

C++

F#

JScript

Copy

// Create a handler for a click event.

button1.Click += delegate(System.Object o, System.EventArgs e)

{ System.Windows.Forms.MessageBox.Show("Click!"); };

VB

C#

C++

F#

JScript

Copy

// Create a delegate.

delegate void Del(int x);

// Instantiate the delegate using an anonymous method.

Del d = delegate(int k) { /* … */ };

By using anonymous methods, you reduce the coding overhead in instantiating delegates because you do not have to create a separate method.

For example, specifying a code block instead of a delegate can be useful in a situation when having to create a method might seem an unnecessary overhead. A good example would be when you start a new thread. This class creates a thread and also contains the code that the thread executes without creating an additional method for the delegate.

VB

C#

C++

F#

JScript

Copy

void StartThread()

{

System.Threading.Thread t1 = new System.Threading.Thread

(delegate()

{

System.Console.Write("Hello, ");

System.Console.WriteLine("World!");

});

t1.Start();

}

Remarks

Lambda Expressions (C# Programming Guide)

http://msdn.microsoft.com/en-us/library/bb397687.aspx

Lambda Expressions (C# Programming Guide)

Visual Studio 2010

Other Versions

·Visual Studio 2008

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

VB

C#

C++

F#

JScript

Copy

delegate int del(int i);

static void Main(string[] args)

{

del myDelegate = x => x * x;

int j = myDelegate(5); //j = 25

}

To create an expression tree type:

VB

C#

C++

F#

JScript

Copy

using System.Linq.Expressions;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Expression<del> myET = x => x * x;

}

}

}

The => operator has the same precedence as assignment (=) and is right-associative.

Lambdas are used in method-based LINQ queries as arguments to standard query operator methods such as Where.

When you use method-based syntax to call the Where method in the Enumerable class (as you do in LINQ to Objects and LINQ to XML) the parameter is a delegate type System.Func<T, TResult>. A lambda expression is the most convenient way to create that delegate. When you call the same method in, for example, the System.Linq.Queryable class (as you do in LINQ to SQL) then the parameter type is an System.Linq.Expressions.Expression<Func> where Func is any Func delegates with up to sixteen input parameters. Again, a lambda expression is just a very concise way to construct that expression tree. The lambdas allow the Where calls to look similar although in fact the type of object created from the lambda is different.

In the previous example, notice that the delegate signature has one implicitly-typed input parameter of type int, and returns an int. The lambda expression can be converted to a delegate of that type because it also has one input parameter (x) and a return value that the compiler can implicitly convert to type int. (Type inference is discussed in more detail in the following sections.) When the delegate is invoked by using an input parameter of 5, it returns a result of 25.

Lambdas are not allowed on the left side of the is or as operator.

All restrictions that apply to anonymous methods also apply to lambda expressions. For more information, see Anonymous Methods (C# Programming Guide).

Expression Lambdas

101 LINQ Samples

http://msdn.microsoft.com/en-us/vcsharp/aa336746

101 LINQ Samples

Restriction Operators

Projection Operators

Partitioning Operators

Ordering Operators

Grouping Operators

Set Operators

Conversion Operators

Element Operators

Generation Operators

Quantifiers

Aggregate Operators

Miscellaneous Operators

Custom Sequence Operators

Query Execution

Utility Routines

Join Operators

Copy all Filenames in a Directory to a Text File

http://txpress.blogspot.com/2008/11/copy-all-filenames-in-directory-to-text.html

Copy all Filenames in a Directory to a Text File

Got to know this last week! This works great if you want to save all the filenames in a directory to a text file.1. Open up your command prompt by typing cmd in the run dialog box and hitting Enter.

2. Navigate to the directory which has the files and type the following command –
DIR /B /O:N > filename.txt
This will save all the filenames in the current directory to a text file. The text file will be saved in the same directory.
3. To save file names from any sub-directories in the current folder, just add /S like –
DIR /B /O:N /S > filename.txt