Linked Questions

2 votes
4 answers
3k views

Possible Duplicates: Why is it bad to use a iteration variable in a lambda expression C# - The foreach identifier and closures From Eric Lippert's 28 June 2010 entry: static IEnumerable<IEnumerable&...
Martijn's user avatar
  • 6,763
2 votes
2 answers
904 views

I wrote a code block, but I am not sure it is thread safe. List<Task> tasks = new List<Task>(); foreach (KeyValuePair<string, string> kvp in result) { var t = new Task(async () =...
Ori Refael's user avatar
  • 3,026
0 votes
2 answers
687 views

Hello people I have a problem using parameters in threads. The problem is that I put an object List<object> as a parameter for a thread array in a foreach loop iterating a list of Lists (List<...
hexehell00's user avatar
2 votes
2 answers
114 views

Here is my code. The log file which is created in the startLog method has proper count from 1 to 1000 but log file being created by log method has duplicate values. For example if 88 is repeated then ...
Kulwinderjit's user avatar
0 votes
1 answer
80 views

can someone tell me why the below is not producing the correct results? It is giving me 1233 when I expected 0123. public static readonly object locker = new object(); public static List<...
user4020465's user avatar
0 votes
2 answers
166 views

Possible Duplicate: C# - The foreach identifier and closures From Eric Lippert’s blog: “don’t close over the loop variable” I'm using a lambda expression as ThreadStart parameter, to run a ...
gliderkite's user avatar
  • 8,928
0 votes
0 answers
71 views

I have a question on this program. It does not produce the correct result. I assume that it should give me output like + 1 + 2 - 1 + 3 - 2 + 4 - 3 + 5 - 4 - 5 (not order specific). However, it outputs ...
Helic's user avatar
  • 949
1 vote
1 answer
57 views

I have a problem that I can't figure out. It might not be easy to explain. I have a singleton class with this private constructor: private BarcodeMonitor() { processors[Machines.H1] = new ...
Halfgaar's user avatar
  • 772
227 votes
12 answers
54k views

What is a closure? Do we have them in .NET? If they do exist in .NET, could you please provide a code snippet (preferably in C#) explaining it?
Developer's user avatar
  • 18.9k
36 votes
5 answers
11k views

While the languages F# and IronPython are technically dissimilar, there is large overlap between their potential uses in my opinion. When is one more applicable than the other? So far it look to me ...
Muhammad Alkarouri's user avatar
41 votes
1 answer
7k views

In this answer https://stackoverflow.com/a/8649429/1497 Eric Lippert says that "FYI we are highly likely to fix this in the next version of C#; this is a major pain point for developers" with regards ...
a_hardin's user avatar
  • 5,277
8 votes
6 answers
2k views

I'm using jQuery and I have a strange thing that I don't understand. I have some code: for (i = 1; i <= some_number; i++) { $("#some_button" + i).click(function() { alert(i); }); } ...
dmitq's user avatar
  • 137
7 votes
2 answers
2k views

Can this be done in a for loop? TickEventArgs targs1 = new TickEventArgs(lbl1_up_time, _elapsedTime_up1); timer_up1.Tick += (sender, e) => Tick(targs1); TickEventArgs ...
dirtyw0lf's user avatar
  • 1,998
1 vote
5 answers
7k views

I am trying to learn Threading in .Net. Many of you must have seen this: private void button1_Click(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(loop)); t.Start(); } ...
Sandy's user avatar
  • 11.7k
3 votes
4 answers
1k views

I'm having problems with this simple code and I don't understand why c# behaves this way. The problem seems to be that c# uses the Linq expression reference instead of the value when using Lists ...
hjgraca's user avatar
  • 1,713

15 30 50 per page