Cannot access a disposed object – How to fix?

Try checking the IsDisposed property before accessing the control. You can also check it on the FormClosing event, assuming you’re using the FormClosed event. We do stop the Timer on the FormClosing event and we do check the IsDisposed property on the schedule component before using it in the Timer Tick event but it doesn’t help. Calling GC.Collect before … Read more

HashSet vs. List performance

A lot of people are saying that once you get to the size where speed is actually a concern that HashSet<T> will always beat List<T>, but that depends on what you are doing. Let’s say you have a List<T> that will only ever have on average 5 items in it. Over a large number of cycles, if a single item … Read more

Difference between decimal, float and double in .NET?

float and double are floating binary point types. In other words, they represent a number like this: The binary number and the location of the binary point are both encoded within the value. decimal is a floating decimal point type. In other words, they represent a number like this: Again, the number and the location of the decimal point are both encoded within the value – that’s … Read more

Cannot access a disposed object – How to fix?

Try checking the IsDisposed property before accessing the control. You can also check it on the FormClosing event, assuming you’re using the FormClosed event. We do stop the Timer on the FormClosing event and we do check the IsDisposed property on the schedule component before using it in the Timer Tick event but it doesn’t help. Calling GC.Collect before … Read more

How to open a new form from another form

In my opinion the main form should be responsible for opening both child form. Here is some pseudo that explains what I would do: You will just need to create a simple event MoreClick in the first child. The main benefit of this approach is that you can replicate it as needed and you can … Read more

Pass Method as Parameter using C#

You can use the Func delegate in .net 3.5 as the parameter in your RunTheMethod method. The Func delegate allows you to specify a method that takes a number of parameters of a specific type and returns a single argument of a specific type. Here is an example that should work:

Merge two (or more) lists into one, in C# .NET

You can use the LINQ Concat and ToList methods: Note that there are more efficient ways to do this – the above will basically loop through all the entries, creating a dynamically sized buffer. As you can predict the size to start with, you don’t need this dynamic sizing… so you could use: (AddRange is special-cased for ICollection<T> for efficiency.) I wouldn’t take this … Read more

Reading CSV file and storing values into an array

I am trying to read a *.csv-file. The *.csv-file consist of two columns separated by semicolon (“;“). I am able to read the *.csv-file using StreamReader and able to separate each line by using the Split() function. I want to store each column into a separate array and then display it. Is it possible to … Read more