Windows Develop Bookmark and Share   
 index > Windows Forms General > Application hangs with a call to MessageBox.Show
 

Application hangs with a call to MessageBox.Show

Hello one and all,

I have problem with my single threaded C# Windows forms application. The application is designed to validate and save up to 600 records into db.
The application actually successfully processes all these records but when showing the result of the operation, (messagebox) the application does not respond with the CPU utilization factor reaching close to 100%. Sometimes after about 15 mins or so the application suddenly responds and sometimes not. This is happening in all the machines.

It would be wonderful if someone can help me out.

Warm regards,
Krishna

Mamidanna  Thursday, May 08, 2008 6:20 PM

There are a lot of reasons that an app can hang like that Since you mention data operations it could be that one of your data objects is trying to run a task without your knowing it. Are you sure that all data operations have fully completed and all the data objects are either closed or disposed of? I coudl easily see a hang like that occurring because a connection or command object has a Timeout property set to 0 (no timeout)or a very high value. Could you post the code surrounding your messagebox call? Maybe there are some clues there?

Dig-Boy  Friday, May 09, 2008 1:09 AM

If you are executing a complex query, then typically the executeReader statement or any of the other command statements can take quite some time before any record is actually returned. It depends on the indexes in the database, the timeout you specified and so on.

If you place a messagebox or a breakpoint on the first processing of a record, then you know for sure that the query is really being executed by your code.

Philip_Stuyck__  Friday, May 09, 2008 5:30 AM
Hello ,

At the outset, I thank you a lot for your time. The application is working perfectly fine and much faster if we run the operations on another thread but I am not supposed to use threads (my Manager does not like it. need more reason). It would be of great help if you can explain as why the app works with multiple threads. Will the allocated memory increase with a new thread?.

Warm regards,
Krishna
Mamidanna  Friday, May 09, 2008 6:15 AM

If you stay within a single method for an extended period of time in a single threaded app, the UI will become unresponsive. The OS detects this and marks the app as such. When you finally exit the method the UI again becomes responsive, but after a delay. Multithreading allows the UI to remain responsive while another non-UI thread remains within a method. You can acomplish the same thing by occasionally (every 100 milliseconds or so) exiting the method. Start a timer, exit the method and when the timer fires, reenter the method.

JohnWein  Friday, May 09, 2008 7:50 AM
Hello John,

Thanks for your time. In the above case you have given, can there be an increase in the CPU utilization factor. This how the app behaves,

While processing the records the CPU utilization is at 100% with windows explorer taking up to 70% and csrss.exe about 30%. The app at this stage is consuming only about 0-5% but when the messagebox.show is called, CPU utilization remains at 100% but this time the app takes up close to 100%. Can you help me understand this behaviour.

Warm Regards,
Krishna
Mamidanna  Friday, May 09, 2008 8:42 AM

You can use google to search for other answers

Custom Search

More Threads

• printing to the printer with vb.net from right to left
• WebBrowser browsing pages with invalid SSL certificate
• Emulate large splitter with controls on it - (example: Roxio Easy CD Creator)
• How to Implement Custom ComboBox?
• CheckedListBox CheckedItems in SelectedValueChanged?
• Autocomplete ComboBox and Binding Error
• DataGridView and CELL FORMAT, becoming crazy with currency cell format!!
• Help with start up of VS2005 app
• ownerdraw textbox
• Droplist with checkboxes visual studio style