Sunday, June 15, 2008

Your crawler freezes? Use BackgroundWorker in C#

When I wrote my first crawler with GUI in C#.NET (I used .NET so that I can create the GUI easily using Visual Studio) I got into a major problem. The GUI got frozen when I ran the crawler... I shared my problem with one of my friend who then told me about BackgroundWorker Thread. Then I got back home, explored BackgroundWorker, learned how to use it, and used it in my crawler and WOW! It worked fine then. So if you get into similar problem then you can also use BackgroundWorker.

You will find it in Toolbox > Component > BackgroundWorker. Just drag it and drop on your form. Right click on it (it's backgroundWorker1 until you change the name) to change it's properties and add events. Now just code the events...

You can go through this example in msdn http://msdn.microsoft.com/en-us/library/b2zk6580.aspx. It's a useful one I think.

2 comments:

Sabbir Yousuf Sanny said...

Very useful information. Thanks!

Unknown said...

Nice Article, Can you please send the sample code for Crawler in C#.net using BackgroundWorker

With Regards
sasikumar
sasi.kandk@gmail.com