Reputation: 153
In a public static class I have the following local method:
private static int GetMaxFromList(IEnumerable<int> list)
{
var result = 0;
foreach (var i in list)
{
if (i > result) result = i;
}
return result;
}
This method is called by some of the public methods within the class (example):
public static bool IsIntegrityOfDataSetGood(DataSet dataSet, KeyValuePair<string, List<int>> tableAndColumnIndexes)
{
return IsIntegrityOfDataSetGood(dataSet, tableAndColumnIndexes.Key) &&
dataSet.Tables[tableAndColumnIndexes.Key].Columns.Count > GetMaxFromList(tableAndColumnIndexes.Value);
}
Note that this public method also calls another public method within the class.
The class methods only work with data sent to them through parameters, but I am worried that the calls between the static methods will mess up thread safety. Am I right to worry?
Forgot to mention that this code resides in a .NET 2.0 project.
Upvotes: 2
Views: 222
Reputation: 1503749
So long as no other threads are changing the list
sequence, it should be absolutely fine. It doesn't access any shared state - it just uses its parameter. If any other thread is modifying the sequence, you'll get an InvalidOperationException
.
It sounds like you may have some misconceptions about thread safety and static methods, but it's hard to tell exactly what they are... you may find Eric Lippert's blog post "What is this thing you call thread safe?" useful.
Upvotes: 3
Reputation: 273824
No, this will not foil your thread-safety.
But whether it really is thread-safe depends on where tableAndColumnIndexes
comes from and what other Threads have access to it. In other words, it depends on the calling code.
Upvotes: 4