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.Threadin g.Thread
NewThread = New System.Threadin g.Thread(Addres sOf 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 8 2440
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
--------------------------
"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.Threadin g.Thread
NewThread = New System.Threadin g.Thread(Addres sOf 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 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?
It might be that your application really needs 100% of the CPU so there is
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.T imer 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
"Luc" <Lu*@discussion s.microsoft.com > schreef in bericht
news:BE******** *************** ***********@mic rosoft.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.Threadin g.Thread
NewThread = New System.Threadin g.Thread(Addres sOf 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
"Luc" <Lu*@discussion s.microsoft.com > wrote in message
news:BE******** *************** ***********@mic rosoft.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.Threadin g.Thread
NewThread = New System.Threadin g.Thread(Addres sOf 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.
To monitor things with a UI try to use BackgroundWorke r. 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" <Lu*@discussion s.microsoft.com > wrote in message news:BE******** *************** ***********@mic rosoft.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.Threadin g.Thread
NewThread = New System.Threadin g.Thread(Addres sOf 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
"Robert" wrote: "Luc" <Lu*@discussion s.microsoft.com > wrote in message news:BE******** *************** ***********@mic rosoft.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.Threadin g.Thread
NewThread = New System.Threadin g.Thread(Addres sOf 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/sm...82#xx1391682xx
"Nicolas Zenou" <Ni**********@d iscussions.micr osoft.com> wrote in message
news:4F******** *************** ***********@mic rosoft.com... To monitor things with a UI try to use BackgroundWorke r. 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" <Lu*@discussion s.microsoft.com > wrote in message news:BE******** *************** ***********@mic rosoft.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.Threadin g.Thread > > NewThread = New System.Threadin g.Thread(Addres sOf 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.
"Luc" <Lu*@discussion s.microsoft.com > wrote in message
news:BB******** *************** ***********@mic rosoft.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?
Timers and Sleep/Doevents sounds way to VB6'ish where we were forced to
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.DoE vents 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/sm...82#xx1391682xx
Hope that helps. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Zuel |
last post by:
Sup everyone!
I wrote this code for Tomcat appserver but I am told from an
associate that it has threading issues. The basic idea is to store a
read only data table for everyone to use. It takes some time for the
table to be created. I want to store the table in a singleton and
update it periodicly, basicaly when a user logs into the system. By
keeping 1 table allocated I don't have to worry about memmory usage
and if a user does...
|
by: Jane Austine |
last post by:
As far as I know python's threading module models after Java's.
However, I can't find something equivalent to Java's interrupt and
isInterrupted methods, along with InterruptedException.
"somethread.interrupt()" will wake somethread up when it's in
sleeping/waiting state.
Is there any way of doing this with python's thread? I suppose thread
interrupt is a very primitive functionality for stopping a blocked
thread.
|
by: James R. Saker Jr. |
last post by:
I've got a: "start server thread > Queue object, start server thread <>
Queue object, start parsing client < Queue object" application that's
got me puzzled. Probably an easy threads issue, but after digging thru
Programming Python and Python Recipes sections on Threading class and
running thru the examples, I'm still missing something.
My Server/Server/Client app is a syslog collector app (syslog input in,
zope control web interface to...
|
by: Jon Skeet [C# MVP] |
last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the
article on all the groups this is posted to.
I've finally managed to finish my article on multi-threading - at least
for the moment. I'd be *very* grateful if people with any interest in
multi-threading would read it (even just bits of it - it's somewhat
long to go through the whole thing!) to check for accuracy,
effectiveness of examples, etc.
Feel free to mail...
|
by: ELO |
last post by:
Hi all
Every week, I need to get two files on a remote server.
I have developped a C# Windows Service with two System.Threading.Timer to do this task
For the first one, the delay (TimeSpan dueTime) is always set to 6 days, 23 hours, 59 minutes, ..
Some weeks ?!?, the timer restarts immediately after its execution (and loop indefinitely). I have made a lot of tests and this issue does not occur with a delay < 1 day ..
Any suggestion
| |
by: John |
last post by:
I've got some reasonably complex business logic in my C# code, in a class
called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not
dependent on SQL calls or anything like that.
I know of the problems with the worker process doing two things at once from
the main thread pool (The old "Sit in a tight loop for 20 seconds and watch
all your webapps die!" issue). So I've worked around the issue by spawning
the business...
|
by: JimD |
last post by:
Is this safe? Any pitfalls? I have done threading in regular C# apps,
but haven't had a needs to do threading in ASP.Net, until now.
The issue I have ran into is this: Our corporate portal application
displays the logged in users 10 most recent emails from Exchange via
WebDav. The current code is in legacy VB6 and needs to be ported
*really* bad. Exchange 2003 has an issue where it only allows a max of
256 WebDav connections from...
|
by: WXS |
last post by:
When I see things in .NET 2.0 like obsoletion of suspend/resume because of
the public reason MS gives of they think people are using them
inappropriately.. use mutex, monitor and other synchronization objects
instead and oh by the way you shouldn't be using them as they can cause
deadlock and other major problems, screams bug or threading architecture
issue and lack of willingness or priority to correct. In reality those API's
are for...
|
by: R K |
last post by:
I am delevoping a Scheduler module whose functionality is to load the Scheduled Item Details every day (For this I have created a System.Threading.TimerCallBack with Timespan 1 day) in a stack. Once the stack is loaded I look for the qualified items every one minute (I create an another TimerCallBack thread). This Scheuler module needs to be started when the UI interface gets loaded.
The issue lies in starting the shceduler since the...
|
by: Dann Corbit |
last post by:
Rather than create a new way of doing things:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html
why not just pick up ACE into the existing standard:
http://www.cse.wustl.edu/~schmidt/ACE.html
the same way that the STL (and subsequently BOOST) have been subsumed?
Since it already runs on zillions of platforms, they have obviously worked
most of the kinks out of the generalized threading and processes idea (along
with many...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |