Click here to Skip to main content
15,920,631 members
Home / Discussions / C#
   

C#

 
AnswerRe: File Properties Pin
engsrini9-Jul-06 22:06
engsrini9-Jul-06 22:06 
QuestiontabControl problem in VS studio 2005 Pin
Kim06189-Jul-06 18:22
Kim06189-Jul-06 18:22 
AnswerRe: tabControl problem in VS studio 2005 Pin
LongRange.Shooter10-Jul-06 4:17
LongRange.Shooter10-Jul-06 4:17 
QuestionHo to Programming for Yahoo messenger ? Pin
hdv2129-Jul-06 13:21
hdv2129-Jul-06 13:21 
AnswerRe: Ho to Programming for Yahoo messenger ? Pin
stancrm9-Jul-06 20:11
stancrm9-Jul-06 20:11 
Questionmulti row select Pin
p_rajanikanth9-Jul-06 13:17
p_rajanikanth9-Jul-06 13:17 
AnswerRe: multi row select Pin
Vipin Venugopal9-Jul-06 18:08
Vipin Venugopal9-Jul-06 18:08 
QuestionWebBrowser + Threads help, please! i dunno what to do anymore... Pin
yoni10009-Jul-06 12:34
yoni10009-Jul-06 12:34 
hey, i'm writing an application which uses a WebBrowser control to navigate a database of sites and do stuff with it.
i know i better use http request but i can't for the specific thing i wanna do.

anyway, my architure is:
WindowForm which creates a single thread, and the thread creates few threads which do all the work.

My problem is, that after an unspecific time, the application hangs... i have no idea why, i've created a message pump inside the small thread with the webbrowser and all threads hang at "DispatchMessage" while teh main thread hangs at m_Smallthread.Start();

This is the code for the main thread:

{
// Fill first the list.
m_lvListView.Invoke(UpdateTheListView, m_dsMyURLs);

// No threads are running.
m_nCurrThreadsRunning = 0;

// This goes over sites.
int nSiteCounter = 0;

// Go over sites
while (nSiteCounter < m_dsMyURLs.Tables[0].Rows.Count)
{
// Check the curr thread num, that is no longer than max boz
if (m_nCurrThreadsRunning < m_nMaxNumberOfThreadsBoz)
{
// Create wanted manual event.
m_StopChildThreads = new ManualResetEvent(false);
m_eSmallThreadStopped = new ManualResetEvent(false);

// Gets real url.
string url;
if (m_dsMyURLs.Tables[0].Rows[nSiteCounter].ItemArray[2].ToString() != "")
{
// Add site name
url = m_dsMyURLs.Tables[0].Rows[nSiteCounter].ItemArray[2].ToString();
}
else
{
// Add site name
url = m_dsMyURLs.Tables[0].Rows[nSiteCounter].ItemArray[1].ToString();
}
try
{
// Create new single getter.
SingleSiteGetter sgSingleGetter =
new SingleSiteGetter(url,
nSiteCounter, EndSingleThreadFunc, m_lvListView,
m_uaArguments, m_StopChildThreads, m_eSmallThreadStopped,
m_nSecsToNavigateWait, m_bDoChilds, ref m_bIsDoEventsLocked);

// Create the thread.
Thread trSingleGetThread = new Thread(sgSingleGetter.StartSmallThread);
trSingleGetThread.Name = "SmallBrowserThread number " + nSiteCounter.ToString();

// Specify it as STA
trSingleGetThread.SetApartmentState(ApartmentState.STA);

Interlocked.Increment(ref m_nCurrThreadsRunning);

// Lock thread, and add it.
Monitor.Enter(m_hThreads);
m_hThreads.Add(m_StopChildThreads, trSingleGetThread);
Monitor.Exit(m_hThreads);


trSingleGetThread.Start();

++nSiteCounter;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}

}
else
{
// Continue if all ok.
Thread.Sleep(300);
}

// Check for canceling
if (ClosureThreadFunc())
{
return;
}
}

// Check that all small threads are done.
while (m_hThreads.Count > 0)
{
// Continue if all ok.
//Application.DoEvents();
Thread.Sleep(500);

// Check for canceling.
if (ClosureThreadFunc())
{
return;
}
}

// Make asynchronous call to main form
// to inform it that thread finished
m_frmPirsumon.Invoke(m_frmPirsumon.m_delegateThreadFinishedEvent, null);
}

* In the above code, we always check if number of threads is not at maximum allowed.

this is the code for small thread:
************************
// Says that its initilizing.
m_lvListView.Invoke(SingleUpdatingProc, m_nSiteIndex, "Starting...", ListViewColums.STATUS);

// Init the web browser (new webbrowser + events).
InitilizeWebBrowser();

// Handle navigation.
int nNavigateResult = Navigate(m_strUrl);
*********

**** This navigates into site: *********
private int Navigate(string strSite)
{
int nResult = ALL_OK;

// Navigate to the wanted url.
m_wbMyBrowser.Navigate(strSite);
DateTime dtNavigatePressTime = DateTime.Now;
m_lvListView.Invoke(SingleUpdatingProc, m_nSiteIndex, "Surfing...", ListViewColums.STATUS);

// Wait till the navigate is completed.
while (nResult == ALL_OK &&
m_wbMyBrowser.ReadyState != WebBrowserReadyState.Complete)
{
// Get how much time passed sience navigation.
TimeSpan tTimeSpent = DateTime.Now.Subtract(dtNavigatePressTime);

// check if time expired.
if (tTimeSpent.TotalSeconds >= m_nSecsToWait)
{
// Stop browser.
// m_wbMyBrowser.Stop();

// Update list
m_lvListView.Invoke(SingleUpdatingProc, m_nSiteIndex, "Error", ListViewColums.STATUS);
m_lvListView.Invoke(SingleUpdatingProc, m_nSiteIndex, "Site did not respond after specified time.", ListViewColums.COMMENTS);
nResult = TIME_ELAPSED;
}

// Check stop event.
else if (m_rsStopIt.WaitOne(0, true))
{
// Stop browser.!
// m_wbMyBrowser.Stop();

m_rSmallIsStoppedNow.Set();

nResult = STOP_PRESSED;
}
else
{
// Handle events.
DoEventsSux();

Thread.Sleep(50);
}
}

return (nResult);

}
My while is checking the state of browser, if time exceeds or stop pressed, it stops it. otherwise, it pumps messages.
my DoEventsSux is a simple peek -> get -> translate -> dispatch that i took from "user32.dll"


thats it, it just hangs everything at some point.
Maybe i did something wrong with the "STA" programming?
i'm at dead end and i'm actually thinking of dropping this project off.. and i've been writing it for a month and a half.

Help!
thanks!!



Ariel.

AnswerRe: WebBrowser + Threads help, please! i dunno what to do anymore... Pin
S. Senthil Kumar9-Jul-06 18:58
S. Senthil Kumar9-Jul-06 18:58 
Questioncan someone post me a simple chat application Pin
lehya9-Jul-06 8:10
lehya9-Jul-06 8:10 
AnswerRe: can someone post me a simple chat application Pin
Ravi Bhavnani9-Jul-06 9:14
professionalRavi Bhavnani9-Jul-06 9:14 
QuestionGet value to byte() [modified] Pin
hung_ngole9-Jul-06 5:57
hung_ngole9-Jul-06 5:57 
AnswerRe: Get value to byte() Pin
Eran Aharonovich9-Jul-06 7:29
Eran Aharonovich9-Jul-06 7:29 
GeneralRe: Get value to byte() Pin
hung_ngole9-Jul-06 16:12
hung_ngole9-Jul-06 16:12 
GeneralRe: Get value to byte() Pin
Eran Aharonovich9-Jul-06 22:42
Eran Aharonovich9-Jul-06 22:42 
AnswerRe: Get value to byte() Pin
Nader Elshehabi9-Jul-06 11:09
Nader Elshehabi9-Jul-06 11:09 
GeneralRe: Get value to byte() Pin
hung_ngole9-Jul-06 16:11
hung_ngole9-Jul-06 16:11 
GeneralRe: Get value to byte() Pin
S. Senthil Kumar9-Jul-06 19:08
S. Senthil Kumar9-Jul-06 19:08 
Questionmore assemblies to one assembly Pin
dedel9-Jul-06 5:48
professionaldedel9-Jul-06 5:48 
AnswerRe: more assemblies to one assembly Pin
Graham Dean9-Jul-06 7:20
Graham Dean9-Jul-06 7:20 
GeneralRe: more assemblies to one assembly Pin
Guffa9-Jul-06 10:42
Guffa9-Jul-06 10:42 
AnswerRe: more assemblies to one assembly Pin
Nader Elshehabi9-Jul-06 11:12
Nader Elshehabi9-Jul-06 11:12 
GeneralRe: more assemblies to one assembly Pin
dedel9-Jul-06 11:31
professionaldedel9-Jul-06 11:31 
AnswerRe: more assemblies to one assembly Pin
Nader Elshehabi9-Jul-06 12:50
Nader Elshehabi9-Jul-06 12:50 
AnswerRe: more assemblies to one assembly Pin
kasik9-Jul-06 13:01
kasik9-Jul-06 13:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.