Thursday, June 25, 2009

Use Beyond Compare with Team Foundation Server in VS 2008/VS2005



VS2008 → Tools → Source Control → Visual Studio Foundation Service → Configure User Tools:
  • Compare → C:\Program Files\Beyond Compare 3\BComp.exe → %1 %2

  • Merge → C:\Program Files\Beyond Compare 3\BComp.exe → %1 %2 /savetarget=%4 /title1=%6 /title2=%7


Sunday, June 21, 2009

Addin favicon to your blog




Here is how to add Favicon to your blog:



ThreadPool.QueueUserWorkItem() could be very slow



ThreadPool.QueueUserWorkItem() could be very slow if callback being executed as a work item calls Thread.Sleep().

Consider the following example:

  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Test
  5. {
  6.   class Program
  7.   {
  8.     const int waitTime = 10000;
  9.     static void Main(string[] args)
  10.     {
  11.       for (int i = 0; i < 10; i++ )
  12.         ThreadPool.QueueUserWorkItem( TestProc, i);
  13.       Console.ReadKey();
  14.     }
  15.  
  16.     static void TestProc(object stateInfo)
  17.     {
  18.       Console.WriteLine("Item number #{0} at {1}", (int)stateInfo, DateTime.Now);
  19.       Thread.Sleep(waitTime);
  20.     }
  21.   }
  22. }


It seems that if waitTime is more than something around 100 ms - .NET thread pool applies some euristic that causes it to start enqueue new thread, while the one that is currently executing is sleeping (seems that it happens every 500ms).
Thus - code above would take around 500ms*10 ~~ 5 sec to complete!!!


Sand Requiem - devoted to soviet soldiers and people fallen in war that started 69 years ago...





Wednesday, June 17, 2009

Howto: publish metadata for net.tcp endpoint and add reference to WCF service hosted in process/service/console



  1. app.config => Edit WCF configuration

  2. Open "Services" section, then "Endpoints" section.

  3. Select an endpoint for which you want to add metadata/MEX endpoint hosted with TCP binding

  4. Endpoints => New service endpoint
    • Set Address to something like net.tcp://localhost:5060/MyEndpointMex

    • Set Name to be something like MyEndpointMex

    • Set Binding to mexTcpBinding

    • Set Contract to IMetadataExchang

    • Set ListenUriMode to Explicit


  5. Advanced => Service Behaviours => Add "New Service Behaviour Configuration"
    Add serviceMedatadata section and set both HttpGetEnabled and HttpsGetEnabled to False

  6. Now start your service process, open VS 2008, select References and then Add Service Reference.
    Put net.tcp://localhost:5060/MyEndpointMex in Address field.

  7. Enjoy




Metadata contains a reference that cannot be resolved net.tcp



Error "Metadata contains a reference that cannot be resolved: 'service reference'.
If the service is defined in the current solution, try building the solution and adding the service reference again." could be caused by specifying specific contract rather than IMetadataExchange in Contract section of service endpoint configuration.

Barrier multithreading primitive in C#






public class Barrier
{
public Barrier(int count)
{
Count = count;
}

public int Count{get; set;}

public void Wait()
{
lock(this)
{
if (--Count > 0)
{
System.Threading.Monitor.Wait(this);
}
else
{
System.Threading.Monitor.PulseAll(this);
}
}
}
}