2

Possible Duplicate:
Implementing RegEx Timeout in .NET 4

Regex regexpr = new Regex(anchorPattern[item.Key], RegexOptions.Singleline, TimeSpan.FromMilliseconds(10));

"System.Text.RegulerExpression.Regex" does not contain a constructer that takes 3 arguments. Note :The error is in the framework 4. if you use the framework 4.5 you won't encounter this error. But i have been using framework 4 and I have to set timeout regexpr. What is the remedy to this ?

Community
  • 1
  • 1
RockOnGom
  • 3,633
  • 5
  • 33
  • 51
  • 1
    Take a look at [Implementing RegEx Timeout in .NET 4](http://stackoverflow.com/questions/9460661/implementing-regex-timeout-in-net-4) - this has an example of how to implement this yourself. (NB It doesn't let you create a `Regex` that inherantly times out, but it lets you time out individual calls to `Match` etc.) – Rawling Nov 23 '12 at 09:47

1 Answers1

3

There is no such constructor as the one you are using in .NET 4. Take a look at documentation page; the only options for constructor are:

Regex()

Regex(String)

Regex(SerializationInfo, StreamingContext)

Regex(String, RegexOptions)

EDIT

You can use a Task to run the regex and Wait method to pass the timeout. Something like this should do the work:

var regexpr = new Regex(anchorPattern[item.Key], RegexOptions.Singleline);
var task = Task.Factory.StartNew(()=>regexpr.Match(foo));
var completedWithinAllotedTime = task.Wait(TimeSpan.FromMilliseconds(10));
Community
  • 1
  • 1
RePierre
  • 9,112
  • 2
  • 21
  • 36