|
Why not!!! Just like list box u can have check box also in ur grid. u can add check box to the item template of the grid. and at the end of the grid give a submit button so that u can do the rest of the process with the selected items.
Vipin
|
|
|
|
|
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.
|
|
|
|
|
Is your main thread the UI thread (the thread on which Application.Run is called)? If so, you're blocking the main thread with the while (m_hThreads.Count > 0) loop. The main thread cannot pump anymore, so any synchronous Invoke would cause the calling thread to hang.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Please help to make a simple chat application using Asp.net C# and XML or SQLserver
|
|
|
|
|
|
Hi,
I have the following code, how can I get the value of the stream into byte array (the response contains binary data and using the readToEnd() fails)
HttpWebResponse response = request.GetResponse()
System.IO.Stream responseStream = response.GetResponseStream()
Thanks in advance,
Hung.
Hung
-- modified at 12:02 Sunday 9th July, 2006
|
|
|
|
|
|
I have the problem with binary data (Ex: image) not the textual data!
Thanks anyway,
Hung.
Hung
|
|
|
|
|
You are right. Sorry.
This is what you need to do:
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://www.noviway.com");
// We use POST ( we can also use GET )
myRequest.Method = "GET";
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse= (HttpWebResponse)myRequest.GetResponse();
// Display the contents of the page to the console.
Stream streamResponse = myHttpWebResponse.GetResponseStream();
MemoryStream memStream = new MemoryStream();
byte[] readBuffer = new byte[256];
// Read from buffer
int count = streamResponse.Read( readBuffer, 0, 256 );
while (count > 0)
{
memStream.Write(readBuffer, 0, count);
// Read from buffer
count = streamResponse.Read( readBuffer, 0, 256);
}
byte[] originalBuffer = memStream.ToArray();
// Release the response object resources.
streamResponse.Close();
// Close response
myHttpWebResponse.Close();
Eran Aharonovich (eran.aharonovich@gmail.com )
Noviway
|
|
|
|
|
Hello
Try this:
HttpWebResponse response = request.GetResponse()
System.IO.Stream responseStream = response.GetResponseStream()
byte[] input = new byte[responseStream.Length];
responseStream.Read(input, 0, (int)responseStream.Length - 1);
Regards
|
|
|
|
|
Although the stream has data, the length of responseStream is -1. This is the main problem I facing !!
Thanks anyway!
Hung.
Hung
|
|
|
|
|
According to the MSDN[^] documentation, Read returns the number of bytes actually read. So you could always create a buffer of some arbitrary size, say 512 bytes, and then loop till Read returns less than 512 bytes. Something like.
ArrayList finalBuffer = new ArrayList();
byte []buffer = new byte[512];
int bytesRead = 0;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
{
for (int i = 0; i<bytesRead; ++i)
{
finalBuffer.Add(buffer[i]);
}
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Is there a chance to compile more assemblies to one assembly ?
|
|
|
|
|
Whereas I am no expert on VS, I have noticed that Dotfuscator Pro has such a facility - the CE edition is supplied free with VS. Search the internet for info. If this doesn't help - sorry but my knowledge is so limited that I am unlikely to be able to help further!
Cheers
Pensioner Graham Dean
|
|
|
|
|
Please don't cross post.
---
b { font-weight: normal; }
|
|
|
|
|
Hello
Please be specific or at least post more details on your question. What do you mean by:
dedel wrote: compile more assemblies to one assembly
Regards
|
|
|
|
|
i want to build a DLL from a collection of DLLs
|
|
|
|
|
Sorry!!
Not if you don't have the source code. Without the source all you can do is referencing.
Regards
|
|
|
|
|
Take a look at ILMerge[^]
“Accept that some days you are the pigeon, and some days you are the statue” -- David Brent
Cheers,
Will
|
|
|
|
|
i have form1 do something. the time required to do is about 2 minutes.
i want to display a form(waiting screen) while form1 complete the task.
my idea is that:
before doing the required task,
- create a new thread.
- open the waiting form in the thread.
- start the thread
it works, but you can access the form1 during doing task.
any idea?
|
|
|
|
|
You can make your waiting form modal and show it in the main thread but process a task in a separate thread.
|
|
|
|
|
many thanks, but how close the modal after the process finished
|
|
|
|
|
Keep reference on the waiting form and close it at the end of the working thread:
private WaitForm waitForm;
private delegate void CloseWaitFormDelegate();
private void StartProcess()
{
Thread processThread = new Thread(new ThreadStart(Process));
waitForm = new WaitForm();
processThread.Start();
waitForm.ShowDialog(this);
}
private void Process()
{
CloseWaitFormDelegate closeWaitForm = new CloseWaitFormDelegate(CloseWaitForm);
Invoke(closeWaitForm);
}
private void CloseWaitForm()
{
if (waitForm != null)
{
waitForm.Close();
waitForm = null;
}
}
-- modified at 4:35 Monday 10th July, 2006
|
|
|
|
|
Hello
You can set the Enabled property of your first form to false; then make it true again when you finish your task.
Form1.Enabled = false;
Form1.ShowWaitScreen();
Form1.DoMyWork();
Form1.CloseWaitScreen();
Form1.Enabled = true
Regards
|
|
|
|
|
If you do a search in CodeProject for SplashScreen you will find an example in there of what you need to do.
|
|
|
|