Im in need of accessing a shared logfile from within my threads, so i now try to use the MethodInvoker to read the file and return a bool depending on if it has found an entry.. But getting this error, cannot figure out how to get it to return me a bool:
Cannot convert anonymous method to delegate type
‘System.Windows.Forms.MethodInvoker’ because some of the return types
in the block are not implicitly convertible to the delegate return
type
private void searchLogInThread(string msg, string fileName)
{
Invoke(new MethodInvoker(
delegate
{
StreamReader re = File.OpenText(fileName);
string input = null;
while ((input = re.ReadLine()) != null)
{
if (input.Contains(msg))
{
re.Close();
return true;
}
}
re.Close();
return false;
}
));
}
Description
The MethodInvoker is a delegate with no result. You need to create your own.
Sample
Update
Another way is to use
Func<bool>More Information