Windows Develop Bookmark and Share   
 index > Windows Forms General > Winform app looping... how can I find out where?
 

Winform app looping... how can I find out where?

Hi,

I have a winform app that is occasionally going into a loop and taking up 99% of CPU.  I have stepped through it with the debugger multiple times and I simply can't work out why it's doing it and it only seems to do when I run it stand-alone (ie: not via VS.Net)... what I want to know is how I could catch the app doing this and then throw an error showing me where it is in the program.  Failing that are there any tools that "profile" the running app so I can try and work out where the blockage is?

TIA for any suggestions or help...

Mike
nzmike  Wednesday, October 19, 2005 4:33 AM
Would something like the CLR Profiler help?
adwins04  Wednesday, October 19, 2005 4:58 AM
Thanks for that - in the meantime I think I've found the problem but I'll check  the profiler out anyway as I could do with knowing about it for the future.

What I did is added a textbox and copious debugging comments and I found out it's a Regex.Match method that's hanging it (or at least taking so much CPU to do the match that it stops the app responding) so now I want to be able to limit the time the Regex takes to work if that's possible.    I'm not sure how you'd go about it - sort of saying "if the match hasn't completed in 1 second then quit and return no match" - can anyone think of a way to do this?  Would a thread be the only way? 

The Regrx code is below and is searching chuncks of HTML for email addresses and URLs.  The HTML is scraped from a client's site and it's only a subset of the whole page's HTML (I extract the HTML between two tags where the emails/urls should be then pass that to the match method) and this seems to be what is causing the Match method to loop.... obviously certain extracts of HTML are just not liked by the Regex engine.

        //Use the specified regex pattern to find email addresses in the spcified HTML.
        public string[] FindEmailAndURLAddresses(string strHTML,string strRegex)
        {

             string strURLRegex = @"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?";
            string strEmailRegex = @"[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})";
 
            string[] strResults = new string[2];

            Regex re = new Regex(strURLRegex,RegexOptions.IgnoreCase);

            // Match the regular expression URL pattern against the HTML.
            Match m = re.Match(strHTML);

            if (m.Success)
                strResults[1] = m.Groups[0].Value;
            else
                strResults[1] = "N/A";

            m = null;

            re = new Regex(strEmailRegex,RegexOptions.IgnoreCase);

            // Match the regular expression email pattern against the HTML.
            Match mx = re.Match(strHTML);

            if (mx.Success)
                strResults[0] = mx.Groups[0].Value;
            else
                strResults[0] = "N/A";

            mx = null;

            return strResults;
           
        }

Hope soneone can suggest something to help out here... not too sure how to control this so it doesn't go into an endless loop!

Mike
nzmike  Wednesday, October 19, 2005 5:17 AM

You can use google to search for other answers

Custom Search

More Threads

• Selecting Server and Database from Combo box in C#
• Hyperlinks
• Windows Child Form Control Box
• iterating through a menustrip
• Problem with Application settings
• Form navigation between forms
• How to achieve my contextMenuStrip look like 3d
• auto alignment of text boxes in windows forms
• How to merge cells in ListView?
• Custom control, custom DataGridViewColumn and Cell - horrible flicker.