Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2007, 02:13 AM
Registered User
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gurupak
Default Abort thread when regular expression get stuck?

Hello,



I have written an application that takes HTML document and apply predefined regular expression on it to parse certain data from the HTML document.

My problem is sometimes the regular expression get stuck and whole application went to Not responding condition. A solution that I implemented in it to recover from it is by using two thread. The first thread is like a monitor to second thread. In this thread I sleep the thread for 30 secs. It checks after 30 secs. if the 2nd thread has not returned properly or it is still running. If it finds it running, it forcefully abort the 2nd third.

private void thread_timer()

{

try

{

string sleep_interval = ConfigurationManager.ConnectionStrings["sleep_interval"].ToString();

while (true)

{

Thread.Sleep(int.Parse(sleep_interval));

if (pattern_thread.IsAlive == true)

{

pattern_thread.Abort();

LoggingManager.LogWriter.Write("Pattern matching thread is aborted.");

break;

}

else

{

LoggingManager.LogWriter.Write("Pattern Thread is already stopped. Aborting Timer Thread.");

break;

}

}

}

catch (Exception exp)

{

LoggingManager.LogWriter.Write("In thread_timer" + exp.Message);


}

}



In second thread the regular expression pattern matching code is executed.

Regex Reg = new Regex(gstrPattern.ToString(), RegexOptions.IgnoreCase | RegexOptions.Singleline);

MatchCol = Reg.Matches(gDocumentHTML.ToString());

To match the pattern in MatchCol global variable.

But this approach is not working sometimes. The pattern thread still remain suspended and it is not aborted through the first timer thread.



Is there any other solution to fix this issue?

Thanks in advance.

Irfan





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Thread.abort nelly78 .NET Framework 2.0 10 April 4th, 2008 01:12 AM
REGULAR EXPRESSION pallone Javascript How-To 0 September 5th, 2006 06:52 AM
regular expression vohra_vikas2004 ADO.NET 3 November 18th, 2004 09:59 PM
regular expression Moharo Pro PHP 3 April 30th, 2004 04:44 AM
Regular Expression Help Hadware .NET Web Services 3 November 4th, 2003 10:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.