p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > C# and C > C# 2005 > C# 2005
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 20th, 2007, 03:13 AM
Registered User
 
Join Date: Mar 2007
Location: Islamabad, Fedral, Pakistan.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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



All times are GMT -4. The time now is 05:38 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc