could any one tell me how ?
-
I have a large code under button_click event. I use XML DB. The code consists of 4 blocks of code after each one I save the data [doc.save("DBFileName.xml")]. Each block (starting from the second one) read from the data that was saved by the previous block, but when I let the 4 blocks to work totally the program stops before completeing the code under button_click event. Nearly half of the tasks are performed and saved then the program stops and does not continue. I want to add a code after each block that make the program to stop for about one or two minutes then continue performing the next block, but I do not know how ? could any one tell me how ?
-
I have a large code under button_click event. I use XML DB. The code consists of 4 blocks of code after each one I save the data [doc.save("DBFileName.xml")]. Each block (starting from the second one) read from the data that was saved by the previous block, but when I let the 4 blocks to work totally the program stops before completeing the code under button_click event. Nearly half of the tasks are performed and saved then the program stops and does not continue. I want to add a code after each block that make the program to stop for about one or two minutes then continue performing the next block, but I do not know how ? could any one tell me how ?
ImanMahmoud wrote: I want to add a code after each block that make the program to stop for about one or two minutes then continue performing the next block, but I do not know how? Well, you could use a timer or suspend your thread to achieve this but somehow I doubt that it will solve your problem. And even if it did it would be a rather dirty hack. ImanMahmoud wrote: Each block (starting from the second one) read from the data that was saved by the previous block, but when I let the 4 blocks to work totally the program stops before completeing the code under button_click event. Nearly half of the tasks are performed and saved then the program stops and does not continue. Have you tried to find out where exactly your application hangs? Knowing which operation causes your application to freeze usually is the first hint in order to solve such a problem. Best regards Dennis
-
I have a large code under button_click event. I use XML DB. The code consists of 4 blocks of code after each one I save the data [doc.save("DBFileName.xml")]. Each block (starting from the second one) read from the data that was saved by the previous block, but when I let the 4 blocks to work totally the program stops before completeing the code under button_click event. Nearly half of the tasks are performed and saved then the program stops and does not continue. I want to add a code after each block that make the program to stop for about one or two minutes then continue performing the next block, but I do not know how ? could any one tell me how ?
It sounds like you probably have a number of performance issues going on here, but let's focus on the obvious. First, your app freezes when the button is clicked because it's single-threaded. You should queue a user work item or spawn a new thread to do the long-running work in the background. Check out this two-part article from Visual Studio Magazine. It covers exactly this topic. http://www.ftponline.com/vsm/2004\_06/magazine/features/jberes Second, you say your program "stops" halfway through. Does "stop" mean it crashes or does it mean it hangs or does it mean it just seemingly mysteriously doesn't do what you expect? Run your code with the Visual Studio debugger and step through it to find the problem. Check the documentation for Visual Studio if you need help with this. Hope this helps
-
It sounds like you probably have a number of performance issues going on here, but let's focus on the obvious. First, your app freezes when the button is clicked because it's single-threaded. You should queue a user work item or spawn a new thread to do the long-running work in the background. Check out this two-part article from Visual Studio Magazine. It covers exactly this topic. http://www.ftponline.com/vsm/2004\_06/magazine/features/jberes Second, you say your program "stops" halfway through. Does "stop" mean it crashes or does it mean it hangs or does it mean it just seemingly mysteriously doesn't do what you expect? Run your code with the Visual Studio debugger and step through it to find the problem. Check the documentation for Visual Studio if you need help with this. Hope this helps
PatrickShane wrote: your app freezes when the button is clicked because it's single-threaded. You should queue a user work item or spawn a new thread to do the long-running work in the background. Threading is not a solution because the 4 blocks must be performed orederly, the 1st is performed and saved then the second, and so on. Furthermore, the 2nd block reads from the data that was saved by the 1st one, and the 3rd reads from the data that was saved by the 2nd, and so on. PatrickShane wrote: Does "stop" mean it crashes or does it mean it hangs or does it mean it just seemingly mysteriously doesn't do what you expect? My application hangs due to overload, because it performe a task then save it the read from what it saved to perfrome the following task the save it, and so on. PatrickShane wrote: Run your code with the Visual Studio debugger and step through it to find the problem. The Visual Studio debugger is not helpful because I ran each block separately (block by block), and each was working and saving correctly.
-
PatrickShane wrote: your app freezes when the button is clicked because it's single-threaded. You should queue a user work item or spawn a new thread to do the long-running work in the background. Threading is not a solution because the 4 blocks must be performed orederly, the 1st is performed and saved then the second, and so on. Furthermore, the 2nd block reads from the data that was saved by the 1st one, and the 3rd reads from the data that was saved by the 2nd, and so on. PatrickShane wrote: Does "stop" mean it crashes or does it mean it hangs or does it mean it just seemingly mysteriously doesn't do what you expect? My application hangs due to overload, because it performe a task then save it the read from what it saved to perfrome the following task the save it, and so on. PatrickShane wrote: Run your code with the Visual Studio debugger and step through it to find the problem. The Visual Studio debugger is not helpful because I ran each block separately (block by block), and each was working and saving correctly.
ImanMahmoud wrote: Threading is not a solution because the 4 blocks must be performed orederly, the 1st is performed and saved then the second, and so on. Threading has nothing at all to do with what order the blocks are processed in. The worker thread can easily preform all the work, in order. "hangs due to overload" doesn't mean much to anyone (and I would suspect that you are mis-interpreting what is happening). More of a code sample might help, but in any case, you should move the entire code out of the click event, and just have the click event start the thread that does the work and return. Have the worker thread signal the UI when it is done (or even signal progress as it works. Anger is the most impotent of passions. It effects nothing it goes about, and hurts the one who is possessed by it more than the one against whom it is directed. Carl Sandburg
-
PatrickShane wrote: your app freezes when the button is clicked because it's single-threaded. You should queue a user work item or spawn a new thread to do the long-running work in the background. Threading is not a solution because the 4 blocks must be performed orederly, the 1st is performed and saved then the second, and so on. Furthermore, the 2nd block reads from the data that was saved by the 1st one, and the 3rd reads from the data that was saved by the 2nd, and so on. PatrickShane wrote: Does "stop" mean it crashes or does it mean it hangs or does it mean it just seemingly mysteriously doesn't do what you expect? My application hangs due to overload, because it performe a task then save it the read from what it saved to perfrome the following task the save it, and so on. PatrickShane wrote: Run your code with the Visual Studio debugger and step through it to find the problem. The Visual Studio debugger is not helpful because I ran each block separately (block by block), and each was working and saving correctly.
ImanMahmoud wrote: Threading is not a solution because the 4 blocks must be performed orederly, the 1st is performed and saved then the second, and so on. You misunderstand me. I didn't mean you need a separate thread for each block of work. I mean you need to move the these 4 blocks of work onto a background thread to get them off the thread that services your WinForm. You can do all 4 blocks in the same background thread in the same order that they're done now. If you leave the long-running work in the main thread, then your application will appear to "hang" to the end user while this work is being performed. Your application won't be able to repaint itself, it won't respond to their mouse clicks, etc. You're setting yourself up for a bad user experience this way. Seriously, go read that 2 part article I gave you a link to. ImanMahmoud wrote: My application hangs due to overload, because it performe a task then save it the read from what it saved to perfrome the following task the save it, and so on. How did you reach the conclusion that you're hanging due to some mysterious "overload" problem? If the code runs correctly in the Visual Studio debugger with the same data you're using when you run it outside of the debugger, then it's highly unlikely that your app is hanging for the reasons you suspect. Do you have PerfMon data to show whether this is a high-CPU-usage hang or a low-CPU-usage hang? Are you calling any of the classes you use from the .Net Framework asynchronously? Have you put any tracing into your code so that you can tell what point your code gets to when the "hang" occurs? Do you have any exception handling in your code? If so, are you swallowing errors that might give you a clue what the problem is? Have you examined your code for infinite loop issues? If you're using large amounts of memory in these 4 blocks of code, then it's possible (but not likely) that .Net garbage collection is running and blocking your app. If that were the issue, then it could appear to you that your application is "hung", but it wouldn't stay in that state forever. Your code would eventually resume. Looking at a "hang" dump of your app's process would be the only way to confirm this. If you've tried everything else that you can think of to determine the source of the "hang", you can always download the Debugging Tools for Windows and use them to take a series of hang dumps of your application. You can then open the hang
-
PatrickShane wrote: your app freezes when the button is clicked because it's single-threaded. You should queue a user work item or spawn a new thread to do the long-running work in the background. Threading is not a solution because the 4 blocks must be performed orederly, the 1st is performed and saved then the second, and so on. Furthermore, the 2nd block reads from the data that was saved by the 1st one, and the 3rd reads from the data that was saved by the 2nd, and so on. PatrickShane wrote: Does "stop" mean it crashes or does it mean it hangs or does it mean it just seemingly mysteriously doesn't do what you expect? My application hangs due to overload, because it performe a task then save it the read from what it saved to perfrome the following task the save it, and so on. PatrickShane wrote: Run your code with the Visual Studio debugger and step through it to find the problem. The Visual Studio debugger is not helpful because I ran each block separately (block by block), and each was working and saving correctly.
You can still do your tasks in a separate thread...I don't think he was suggesting that you create multiple threads for each block of code. Create one, let it do all of your tasks, just as your button event handler would have. At least this way you'll have control of your window. How long is your applications "hanging"? If it never stops hanging, then it's not an issue with overload, there's something in your code that is causing the application to hang. Step through it line by line to see exactly what is going on.