Debug Windows Service

I recommend following pattern for debug: var ServiceToRun = new SomeService(); if (Environment.UserInteractive) { // This used to run the service as a console (development phase only) ServiceToRun.Start(); Console.WriteLine(“Press Enter to terminate …”); Console.ReadLine(); ServiceToRun.DoStop(); } else { ServiceBase.Run(ServiceToRun); } Edit: make sure that your target is Console Application, not Windows Application, otherwise it will … Read more

Scroll WPF ListBox to the SelectedItem set in code in a view model

Have you tried using Behavior… Here is a ScrollInViewBehavior. I have used it for ListView and DataGrid….. I thinks it should work for ListBox…… You have to add a reference to System.Windows.Interactivity to use Behavior<T> class Behavior public class ScrollIntoViewForListBox : Behavior<ListBox> { /// <summary> /// When Beahvior is attached /// </summary> protected override void … Read more

Avoid Adding duplicate elements to a List C#

You can use Enumerable.Except to get distinct items from lines3 which is not in lines2: lines2.AddRange(lines3.Except(lines2)); If lines2 contains all items from lines3 then nothing will be added. BTW internally Except uses Set<string> to get distinct items from second sequence and to verify those items present in first sequence. So, it’s pretty fast.