21

I have an C# application in which I am getting this error :

"Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation."

I saw many posts related to this error on stackoverflow and on msdn also but found no solution. Most of the people say that this error comes in multithreaded application and can be resolved by deleting all the breakpoints. In my case, my app is single threaded and I have deleted all the breakpoints also but still I am getting this error when I debug the app. When I run the app. without debugging, my application just hangs and I have to stop it throught visual studio. I tried to find the code where its getting hang and I found the line where it gets hang. Here is the code snippet :

MatchCollection matchesFound = Regex.Matches(content, 
                                             keywordPattern,
                                             RegexOptions.Multiline);
int matchCount = matchesFound.Count;

When execution comes at second line, i.e. when code tries to get the value of Count property my application gets hang. My regular expression is fine as I have tested it in Expresso and I am sure that application is not getting hanged while executing Matches() method. If I come to that line by debugging, I get the above mentioned error. Does anyone knows why this error comes and how to resolve it?

I am using Visual studio 2005.

Shekhar
  • 11,438
  • 36
  • 130
  • 186
  • My regex is dynamic based on keywords mentioned in one file. I read those keywords from file and form regex. I have tested that regex in Expresso and it worked fine without getting hanged in expresso. Also, while debugging I have found that my app. does not hang at Matches() method. – Shekhar Apr 27 '10 at 12:34
  • 1
    I think you should post a sample regex and the test string - or even better: a minimized compile-n-run-n-reproducible version of the whole code. – Amarghosh Apr 27 '10 at 12:49

1 Answers1

9

The reasons of the hang and of this error message are probably the same: there is something that takes a lot of time to compute. Both when you do it in code and in debugger. Debugger has no magic power to calculate something faster than your app.

You can try to use Debug.WriteLine to output actual content and keywordPattern. I think it easily might be that both are big enough to take ages to proceed.

SergGr
  • 23,570
  • 2
  • 30
  • 51
  • hmm.. ok.. The reason behind I said that my regex is fine is that, Regex.Matches() method executes without taking too much time. my app. hangs only when I try to get the count property of MatchCollection object. Anyways, I will recheck my regex once more and I will also put sample regex here. Thanks for help !! – Shekhar Apr 29 '10 at 05:23
  • 5
    `Regeex.Matches()` does almost nothing. `MatchCollection` contents is **lazy** calculated. It is first call to something like `Count` that makes it find all matches. So there are no surprises here. I still think that `content` is big and `keywordPattern` is complicated. You might have to rethink your logic. Maybe there is a way to calculate what you need in much faster way. Actually "How to calculate something efficiently? might be better question to ask here than "Why my program runs so slowly?". – SergGr Apr 29 '10 at 10:03