Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I wrote An multi-thread application to extract list of friends from a web page such as an online social network by C#. unfortunately My Form hangs and dont response to anything.(freezing) what could i do?
I would appreciate your help.
thanks a lot.

my Code is:
C#
/.................................................................
private void BtnBFS_Click(object sender, EventArgs e)
{
Thread[] SpiderThread = new Thread[n];
object[] Param = new object[n];
ThreadCount = n;
for (int i = 0; i < n; i++)
Param[i] = TxtURL.Lines[i].ToString();
for (int Index = 0; Index < n; Index++)
{
SpiderThread[Index] = new Thread(BFS);
SpiderThread[Index].Name = Index.ToString();
}
for (int i = 0; i < n; i++)
SpiderThread[i].Start(Param[i]);
for (int i = 0; i < n n; i++)
SpiderThread[i].Join();
}
/////............................................................
public void BFS(object Param)
{
try
{
define some variable
while (UnCrawledQueue.Count >= 0 and visited <= NumC)
{
main process;
}
}
}
Posted
Updated 29-Jul-15 20:58pm
v3
Comments
Dave Kreskowiak 29-Jul-15 17:35pm    
Without seeing your code it's impossible to say what's wrong.

But, changes are really good that you're doing everything on the UI thread, blocking any updates to the form until the code is done processing whatever you're doing.

YOU may say that's it's "multithreaded" but it's what the code says that's important.

1 solution

Remove the SpiderThread[i].Join(); line. When you call Join on a thread it blocks the calling thread (in your case: the UI thread) until the thread has finished its work.

 
Share this answer
 
Comments
Member 11762992 30-Jul-15 3:06am    
i have done it.it works.thanks. but i want to after all threads end,show a message and call some function. what can i do?
Shmuel Zang 30-Jul-15 4:30am    
You have got some suggestions for it here: How Can I Call Some Function After All Threads End?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900