Wednesday, January 17, 2007

Tip : SP1 solves Visual Studio 2005 Performance Issues!

I experienced some performance issues with visual studio 2005 yesterday, it started with taking long time to save a file, I thought that I have changed something, or added add-on that caused this to happen, also it took longer time to open the IDE, although I have a dual core with 3 G of memoory...

but thanks god, I downloaded sp1 from http://www.microsoft.com/downloads/details.aspx?familyid=BB4A75AB-E2D4-4C96-B39D-37BAF6B5B1DC&displaylang=en , it took some time to install but it the problem has gone immediatly !

Friday, January 12, 2007

Regex hangs with complicated expressions or long string inputs, the Solution

After some struggles and wondering why my application hangs sometimes without throwing any exceptions or errors in event log entries, I was able to find out that the Regex in .Net was the issue.
so I started investigating and there are some nice handy solutions online but it's little sophsiticated and coupled specifically with regular expressions, while if you use the ThreadPool class, it's much easier to control threads and start asynchronous processes and wait for it a for a certain amount of time until it either finishes or the time is up.

here is all what you need (vb.net 2.0 .net framework)!

Imports System.Threading
'you create a threadnotify object to monitor the asynchronous process
Dim ThreadNotify As AutoResetEvent = New AutoResetEvent(False)
'start the process
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf StartMyAsyncProcess), ThreadNotify)
'wait 1.5 seconds , if the time is over, the thread will halt itself and this program will resume.
ThreadNotify.WaitOne(1500, True)
end sub
'the asynch process
Private Sub StartMyAsyncProcess(ByVal state As Object)
in_string = Regex.Replace(in_string, "\s*\r\n\s*", vbNewLine)
state.set()
End Sub