|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB.NET Threading CPU Issueset up the tests, and once this is complete, I open 4 identical forms to monitor each different device that I am automating. Because there are many fast timers on each, I have placed each one of these forms in their own thread by using the following code: Dim NewForm As New frmFormName Dim NewThread As System.Threading.Thread NewThread = New System.Threading.Thread(AddressOf NewRadio.Show) NewThread.Start() NewThread = Nothing NewRadio = Nothing Anyway, everything works fine, but when I try and minimize or maximize a window in a different program, my CPU Usage goes to 100% and stays there until I stop my automation application. Does anyone know how I can fix this? Thanks, Luc Hi,
A thread runs in the background. It will keep the users computer from feeling like it is locked up but your cpu might go to 100%. Ken -------------------------- Show quoteHide quote "Luc" wrote: > Hi, I am writing software to automate some testing. I have one main form to > set up the tests, and once this is complete, I open 4 identical forms to > monitor each different device that I am automating. Because there are many > fast timers on each, I have placed each one of these forms in their own > thread by using the following code: > > Dim NewForm As New frmFormName > Dim NewThread As System.Threading.Thread > > NewThread = New System.Threading.Thread(AddressOf NewRadio.Show) > NewThread.Start() > > NewThread = Nothing > NewRadio = Nothing > > Anyway, everything works fine, but when I try and minimize or maximize a > window in a different program, my CPU Usage goes to 100% and stays there > until I stop my automation application. Does anyone know how I can fix this? > > Thanks, > > Luc > > On Wed, 7 Jun 2006 11:49:43 -0700, Luc wrote:
> Hi, I am writing software to automate some testing. I have one main form to It might be that your application really needs 100% of the CPU so there is> set up the tests, and once this is complete, I open 4 identical forms to > monitor each different device that I am automating. Because there are many > fast timers on each, I have placed each one of these forms in their own > thread by using the following code: [...] > Anyway, everything works fine, but when I try and minimize or maximize a > window in a different program, my CPU Usage goes to 100% and stays there > until I stop my automation application. Does anyone know how I can fix this? no reason why Windows would not give it to your application as long as no other application needs it. However, it might also be a problem with your application. Playing with UI controls in different thread is a very tricky subject and should be avoided unless you really know what you are doing. You must make sure that controls in a given thread never interact in any way with controls in another thread (for example, you cannot have a form in thread 1 parent of a control or form in thread 2). Also, you must make sure that all the calls to control's methods are properly marshalled to their respective threads. Also keep in mind that if your system only has one CPU, then it will only be able to do one thing at a time no matter how many threads you have started. Even if you use 10000 threads, it won't run faster than if you only has 1 thread. In fact, it would actually be slower since Windows would need to constantly do thread context switches, which takes time. From what you've said, it doesn't look like you really need to have 1 form per thread. You could have your 4 forms in the UI thread and then have your business logic running in 4 different threads. Or don't even start threads at all and use a System.Timers.Timer which will call its callback method in a thread from the thread pool from where you'll be able to do whatever you want to do. Luc,
100% processing time means mostly a continues loop inside one of your threads. Cor Show quoteHide quote "Luc" <L**@discussions.microsoft.com> schreef in bericht news:BE83790B-D782-4296-92D4-F78166A0B77F@microsoft.com... > Hi, I am writing software to automate some testing. I have one main form > to > set up the tests, and once this is complete, I open 4 identical forms to > monitor each different device that I am automating. Because there are > many > fast timers on each, I have placed each one of these forms in their own > thread by using the following code: > > Dim NewForm As New frmFormName > Dim NewThread As System.Threading.Thread > > NewThread = New System.Threading.Thread(AddressOf NewRadio.Show) > NewThread.Start() > > NewThread = Nothing > NewRadio = Nothing > > Anyway, everything works fine, but when I try and minimize or maximize a > window in a different program, my CPU Usage goes to 100% and stays there > until I stop my automation application. Does anyone know how I can fix > this? > > Thanks, > > Luc > >
Show quote
Hide quote
"Luc" <L**@discussions.microsoft.com> wrote in message I just did some work on an app like this.news:BE83790B-D782-4296-92D4-F78166A0B77F@microsoft.com... > Hi, I am writing software to automate some testing. I have one main form > to > set up the tests, and once this is complete, I open 4 identical forms to > monitor each different device that I am automating. Because there are > many > fast timers on each, I have placed each one of these forms in their own > thread by using the following code: > > Dim NewForm As New frmFormName > Dim NewThread As System.Threading.Thread > > NewThread = New System.Threading.Thread(AddressOf NewRadio.Show) > NewThread.Start() > > NewThread = Nothing > NewRadio = Nothing > > Anyway, everything works fine, but when I try and minimize or maximize a > window in a different program, my CPU Usage goes to 100% and stays there > until I stop my automation application. Does anyone know how I can fix > this? Run one main thread with all the GUI stuff.. Run your worker threads at belownormal priority. Otherwise all your threads will run by default at normal priority, and the screen redraws may never have time to finish before they are preempted by your other threads. This leads to an unresponsive app. To monitor things with a UI try to use BackgroundWorker. Its' new in .NET
Framework 2.0 and allow multithreading without freezing your UI (100% CPU). Let me know if it's help. Truly, ZENOU Nicolas. Show quoteHide quote "Robert" wrote: > > "Luc" <L**@discussions.microsoft.com> wrote in message > news:BE83790B-D782-4296-92D4-F78166A0B77F@microsoft.com... > > Hi, I am writing software to automate some testing. I have one main form > > to > > set up the tests, and once this is complete, I open 4 identical forms to > > monitor each different device that I am automating. Because there are > > many > > fast timers on each, I have placed each one of these forms in their own > > thread by using the following code: > > > > Dim NewForm As New frmFormName > > Dim NewThread As System.Threading.Thread > > > > NewThread = New System.Threading.Thread(AddressOf NewRadio.Show) > > NewThread.Start() > > > > NewThread = Nothing > > NewRadio = Nothing > > > > Anyway, everything works fine, but when I try and minimize or maximize a > > window in a different program, my CPU Usage goes to 100% and stays there > > until I stop my automation application. Does anyone know how I can fix > > this? > > > I just did some work on an app like this. > > Run one main thread with all the GUI stuff.. > Run your worker threads at belownormal priority. > > Otherwise all your threads will run by default at normal priority, and the > screen redraws may never have time to finish before they are preempted by > your other threads. This leads to an unresponsive app. > > > I fiddled with that a bit, but found that SmartThreadPool had done a lot
things I needed, already working. With 4 image controls fighting for new images, and only 2 cores, it was necessary to queue the items, so that image control #1 did not get 2, while number 4 got skipped. The images can be of different resolution, and can have much different decode times. http://www.codeproject.com/csharp/smartthreadpool.asp?df=100&forumid=88599&exp=0&select=1391682#xx1391682xx Show quoteHide quote "Nicolas Zenou" <NicolasZe***@discussions.microsoft.com> wrote in message news:4FC7D63C-ECFE-4754-AFD3-D6D81E854C13@microsoft.com... > To monitor things with a UI try to use BackgroundWorker. Its' new in .NET > Framework 2.0 and allow multithreading without freezing your UI (100% > CPU). > > Let me know if it's help. > > Truly, > ZENOU Nicolas. > > "Robert" wrote: > >> >> "Luc" <L**@discussions.microsoft.com> wrote in message >> news:BE83790B-D782-4296-92D4-F78166A0B77F@microsoft.com... >> > Hi, I am writing software to automate some testing. I have one main >> > form >> > to >> > set up the tests, and once this is complete, I open 4 identical forms >> > to >> > monitor each different device that I am automating. Because there are >> > many >> > fast timers on each, I have placed each one of these forms in their own >> > thread by using the following code: >> > >> > Dim NewForm As New frmFormName >> > Dim NewThread As System.Threading.Thread >> > >> > NewThread = New System.Threading.Thread(AddressOf NewRadio.Show) >> > NewThread.Start() >> > >> > NewThread = Nothing >> > NewRadio = Nothing >> > >> > Anyway, everything works fine, but when I try and minimize or maximize >> > a >> > window in a different program, my CPU Usage goes to 100% and stays >> > there >> > until I stop my automation application. Does anyone know how I can fix >> > this? >> >> >> I just did some work on an app like this. >> >> Run one main thread with all the GUI stuff.. >> Run your worker threads at belownormal priority. >> >> Otherwise all your threads will run by default at normal priority, and >> the >> screen redraws may never have time to finish before they are preempted by >> your other threads. This leads to an unresponsive app. >> >> >> Thank you everyone for the replies, you've been of so much help! I managed
to fix the 100% problem by using the sleep method for 1 millisecond every time my timer method runs. I now have a new problem :-S. I am using two ccrp timers on each of the four forms. One to update a clock to show the time, and one in a dll to run all the automation routines. Because I want the clocks on each to update at the same time, I have the timers running really fast, and because of the required accuracy of the automation processes, the second timer is running really fast. If I start the entire thing and don't touch anything else, the program works as it should. However, if I minimize or maximize a different window other than that four forms after the program has been started, the second ccrp timer (located in the dll) on each form either fails to run when it should, or just run once and then never again. Would anyone have an idea how to fix this? Thanks, Luc Show quoteHide quote "Robert" wrote: > > "Luc" <L**@discussions.microsoft.com> wrote in message > news:BE83790B-D782-4296-92D4-F78166A0B77F@microsoft.com... > > Hi, I am writing software to automate some testing. I have one main form > > to > > set up the tests, and once this is complete, I open 4 identical forms to > > monitor each different device that I am automating. Because there are > > many > > fast timers on each, I have placed each one of these forms in their own > > thread by using the following code: > > > > Dim NewForm As New frmFormName > > Dim NewThread As System.Threading.Thread > > > > NewThread = New System.Threading.Thread(AddressOf NewRadio.Show) > > NewThread.Start() > > > > NewThread = Nothing > > NewRadio = Nothing > > > > Anyway, everything works fine, but when I try and minimize or maximize a > > window in a different program, my CPU Usage goes to 100% and stays there > > until I stop my automation application. Does anyone know how I can fix > > this? > > > I just did some work on an app like this. > > Run one main thread with all the GUI stuff.. > Run your worker threads at belownormal priority. > > Otherwise all your threads will run by default at normal priority, and the > screen redraws may never have time to finish before they are preempted by > your other threads. This leads to an unresponsive app. > > >
Show quote
Hide quote
"Luc" <L**@discussions.microsoft.com> wrote in message Timers and Sleep/Doevents sounds way to VB6'ish where we were forced to news:BB7A06C6-2C0A-4226-BD77-0B94121894D3@microsoft.com... > Thank you everyone for the replies, you've been of so much help! I > managed > to fix the 100% problem by using the sleep method for 1 millisecond every > time my timer method runs. I now have a new problem :-S. > > I am using two ccrp timers on each of the four forms. One to update a > clock > to show the time, and one in a dll to run all the automation routines. > Because I want the clocks on each to update at the same time, I have the > timers running really fast, and because of the required accuracy of the > automation processes, the second timer is running really fast. If I start > the entire thing and don't touch anything else, the program works as it > should. However, if I minimize or maximize a different window other than > that four forms after the program has been started, the second ccrp timer > (located in the dll) on each form either fails to run when it should, or > just > run once and then never again. > > Would anyone have an idea how to fix this? simulate threads by sharing one thread among several activities.. Also, stay far away from SendKeys. ..Net has much more effective and efficient ways to synchronize threads than timers. Your architecture seems WAY too complicated to me. 1) All .Net apps by default have one main thread. The GUI will run on it. Designate this thread as the "Boss". 2) Have the boss thread have one timer to fire every 100ms. 3) When the timer fires, delegate chunks of work to each of the worker threads(running at BelowNormal priority). Boss is now idle. Yielding to lower priority threads. 4) Have the worker threads fire an event back to the main GUI including the results of the work 5) The boss thread will then display the results on the next context switch. Maybe call Application.DoEvents here, to flush the message queue. 6) if you resize the main window, the boss will again have some work to do, and being at a higher priority, will step forward, and handle the resize. When all events are processed, boss is again idle, allowing the workers another go. Not saying the above is the absolute best way, but it has clean readable code, behaves well, and gives a responsive app. I found it solved all the issues in my app. I found this useful to queue up a bunch of work items, so they did not get out of order, or in each others way. It also has some good info on threading in general. http://www.codeproject.com/csharp/smartthreadpool.asp?df=100&forumid=88599&exp=0&select=1391682#xx1391682xx Hope that helps.
le nom 'vb6' n'est pas déclaré
Overload resolution failed All I'm looking for is a simple answer to a simple question DataGrid Control How do I use a class, when the class requires functions in the main form? Object-to-Relational Tool Memory Manipulation Error while file copying over network. Unmanaged C++ Void* Use HideDragon to Quick hide window, the best Boss key! |
|||||||||||||||||||||||