.Net

How to run asynchron Operations in C#

using System;
using System.Threading;
using System.Threading.Tasks;
This example example includes a call to the Task.Wait method to ensure that the task completes execution before the console mode application ends.

public class Example
{
public static void Main()
{
Thread.CurrentThread.Name = "Main";

// Create a task and supply a user delegate by using a lambda expression.
Task taskA = new Task( () => Console.WriteLine("Hello from taskA."));
// Start the task.
taskA.Start();

// Output a message from the calling thread.
Console.WriteLine("Hello from thread '{0}'.",
Thread.CurrentThread.Name);
taskA.Wait();
}
}
// The example displays the following output:
// Hello from thread 'Main'.
// Hello from taskA.

Taggings:

How to run asynchron Operations in C#

Its import how a Task is working. There are many ways to run asynchron operations. Sometimes you also need return values from a Task or you want to cancel/stop the Task clean. For how to cancel a task please read the section for Cancellation Token. More informations you can find on MSDN. http://msdn.microsoft.com/en-us/library/dd537609%28v=vs.110%29.aspx Here you can see a codesnippet how easy it is to deal with Tasks.

Add email to list in Mailchimp

There are basicaly two ways to add multiple new users to a mailing list:
import a list:
http://kb.mailchimp.com/article/how-do-i-create-and-import-my-list
or to use the provided MailChimp-API:
for .net the are API-Wrappers (https://github.com/danesparza/MailChimp.NET, or https://github.com/danesparza/MailChimp.NET) available which makes the MailChimp-API easy to use. In the end its just about manipulating an object and passing it to a method.

MailChimpManager mc = new MailChimpManager("6e0fc756762e0234f06bfa27f5bbe-us7");

EmailParameter email = new EmailParameter(){ Email = txt_Mail.Text };

Dictionary attributes = new Dictionary();
attributes.Add("FNAME", txt_FirstName.Text);
attributes.Add("LNAME", txt_LastName.Text);

EmailParameter results = mc.Subscribe(Util.GetMailchimpListID(), email, attributes);

Taggings:

NUnit for unit-testing

NUnit is an unit testing framework for the .Net framework and is based on JUnit.

Minimal setup:

For making a test case, a normal c# class is created, which imports the NUnit framework.

using NUnit.Framework

The class must have the attribute [TextFixture] to indicate, that this class has test code.
The attributes [SetUp] and [TearDown] are optional and can be used if some pre/post conditions are need for each test (e.g. resetting the DB).

The different test cases are marked by the attribute [Test]. Different static methods of the Assert class are used for checking the results.

Example:

[TextFixture]
public class MyTests
{
[SetUp]
public void setup()
{
//fill database with test data
}

[TearDown]
public void tearDown()
{
//delete data in database
}

[Test]
public void test1()
{
user = ... //search for user by id
Assert.AreEqual(name, user.name);
}
}

Taggings:

Making unit tests for .NET framework in Visual Studio 2008

Finding a tool for automated unit tests that works with the .NET Framework. The backend classes are written in C# and the IDE i am using is Microsoft Visual Studio 2008.

How can the creation of WCF or ASMX Web Services be simplified at high quality level?

<p>&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">Is there a way to increase the speed of overall web service development using .NET and preferrable WCF. This overall procedure should include the implementation, the testing, the support for documentation and the maintenance and feature extending in the future.</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949; min-height: 15.0px;">&nbsp;</p> <p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">Automatic code generation (server &amp; client) using patterns or strict conventions is preferred due to an easier communicatable result, because we use web services in way that they the user easily recognizes which parameters are requested and which are returned without searching through structures and procedures. The generation of tests should be possible at least on "Test shell" basis that can be completed. The generation should never remove own written code.</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">Additonally, the code generation should be possible for WCF and classical (ASMX) Web Services using the same input values.&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">Naturally, we do not want to use the configurability of web services. It must be able to create unsecured / open web services without authtentication, but it should also be possible to secure them. Several different binding variants are used in our system at the moment and we typically publish our services several times on different machines addressing different users. This should be easier to configure and use in the future.&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">&nbsp;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; line-height: 20.0px; font: 12.0px Verdana; color: #494949;">&nbsp;</p><p>&nbsp;</p>
Subscribe to .Net