473,769 Members | 7,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Higher CPU Utilization on Windows form resize

I have created a windows application in which the form needs to be
resized on the MouseMove event. The windows resize function takes a lot
of CPU cycles. And as the resize function is called on the MouseMove,
the form is resized around a 30-100 times in one second. This leads to
a high CPU utilization and all other application comes to a stand
still.

The form does not have any controls i.e. buttons, text boxes etc. It is
completely empty. Its opacity in around 10%.

Now is there any way by which we can reduce all the amount of CPU taken
by the form on resize??

Or can I reduce the form resize calls on MouseMove event. i.e. some way
by which all the mouse move event don't lead to form resize.

Please help me out with this.

Nov 13 '06 #1
11 3475
You can block the painting of the form partially.

Be aware that this can give an elastic effect if you don't do it in short
steps.

Cor

"Ajith Menon" <ko********@gma il.comschreef in bericht
news:11******** *************@f 16g2000cwb.goog legroups.com...
>I have created a windows application in which the form needs to be
resized on the MouseMove event. The windows resize function takes a lot
of CPU cycles. And as the resize function is called on the MouseMove,
the form is resized around a 30-100 times in one second. This leads to
a high CPU utilization and all other application comes to a stand
still.

The form does not have any controls i.e. buttons, text boxes etc. It is
completely empty. Its opacity in around 10%.

Now is there any way by which we can reduce all the amount of CPU taken
by the form on resize??

Or can I reduce the form resize calls on MouseMove event. i.e. some way
by which all the mouse move event don't lead to form resize.

Please help me out with this.

Nov 13 '06 #2
"Ajith Menon" <ko********@gma il.comwrote in message
news:11******** *************@f 16g2000cwb.goog legroups.com...
[...]
Now is there any way by which we can reduce all the amount of CPU taken
by the form on resize??

Or can I reduce the form resize calls on MouseMove event. i.e. some way
by which all the mouse move event don't lead to form resize.
You don't want to do that. After all, if the user is dragging the form to
resize it, ignoring some of the mouse moves will result in the user not
being able to resize to exactly whatever size they want.

However, as far as the actual problem goes...the CPU consumption is from
redrawing the form every time it's resized. Set the form to not draw during
resizing, and the CPU use will go down (it can't be eliminated, since there
will always be some feedback to the user about the resizing).

If you really think it's necessary, you can disable resize redrawing, but
then handle the resize events yourself and explicitly redraw (invalidate the
form) every so often, as a way of reducing the redraw events.

Pete
Nov 13 '06 #3
Thanks for your immdiate response.
However, as far as the actual problem goes...the CPU consumption is from
redrawing the form every time it's resized. Set the form to not draw during
resizing, and the CPU use will go down (it can't be eliminated, since there
will always be some feedback to the user about the resizing).
How to set the form not to redraw during resize?
Also I got to know the higher processor is due to opacity=10%. The
foreground repaint as well as background repaintis called. In case if
opacticy is 100% background repaint is not called.
>You can block the painting of the form partially.

Be aware that this can give an elastic effect if you don't do it in short
steps.
And what is blocking the painting partially???

Thanks,
Ajith

Nov 13 '06 #4
Hi Ajith,
I suspect that it is the transparency that is causing you to use more CPU
cycles during a resize because transparency require more calculation that an
opaque window. Try making the form opaque when you resize and turn the
transparency back on after the resizing has occured and see if that improves
your situation.

Mark.
--
http://www.markdawson.org
"Ajith Menon" wrote:
I have created a windows application in which the form needs to be
resized on the MouseMove event. The windows resize function takes a lot
of CPU cycles. And as the resize function is called on the MouseMove,
the form is resized around a 30-100 times in one second. This leads to
a high CPU utilization and all other application comes to a stand
still.

The form does not have any controls i.e. buttons, text boxes etc. It is
completely empty. Its opacity in around 10%.

Now is there any way by which we can reduce all the amount of CPU taken
by the form on resize??

Or can I reduce the form resize calls on MouseMove event. i.e. some way
by which all the mouse move event don't lead to form resize.

Please help me out with this.

Nov 13 '06 #5

Mark R. Dawson wrote:
Hi Ajith,
I suspect that it is the transparency that is causing you to use more CPU
cycles during a resize because transparency require more calculation that an
opaque window. Try making the form opaque when you resize and turn the
transparency back on after the resizing has occured and see if that improves
your situation.

Mark.
--
But the requirement is that the form should remain transparent during
resize so that the user can see the items behind the form.
It is something like the user creates this transparent rectangle (i.e.
the form 10% opacity), over other items. All the items that come under
this rectangular region will be copied to the clipboard as .bmp file.

Nov 13 '06 #6
What kind of degredation are you seeing? I set a form to 10% opacity and was
playing a video in my web browser, playing music with a visualization playing
and everything played fine while resizing the form, the CPU was at 100% but
that is okay. I was also running the app in debug mode, my laptop is not
great only 1.8GHz and 768MB of RAM.

Mark.
--
http://www.markdawson.org
"Ajith Menon" wrote:
>
Mark R. Dawson wrote:
Hi Ajith,
I suspect that it is the transparency that is causing you to use more CPU
cycles during a resize because transparency require more calculation that an
opaque window. Try making the form opaque when you resize and turn the
transparency back on after the resizing has occured and see if that improves
your situation.

Mark.
--

But the requirement is that the form should remain transparent during
resize so that the user can see the items behind the form.
It is something like the user creates this transparent rectangle (i.e.
the form 10% opacity), over other items. All the items that come under
this rectangular region will be copied to the clipboard as .bmp file.

Nov 13 '06 #7
Mark R. Dawson wrote:
What kind of degredation are you seeing? I set a form to 10% opacity and was
playing a video in my web browser, playing music with a visualization playing
and everything played fine while resizing the form, the CPU was at 100% but
that is okay. I was also running the app in debug mode, my laptop is not
great only 1.8GHz and 768MB of RAM.

Mark.
I have this transparent form within other application which has many
other forms. The other forms get dynamic data and gets updated
regularly. These other forms of the same application starts degrading
i.e. the dynamic data stop coming on it.

Nov 13 '06 #8
Okay, well that makes sence since the issue will be that the transparent form
and the controls will be using the main UI thread to update, since the form
is resizing and taking most of the processing time the other controls do not
get chance to update.

What you can do is create your transparent form on a new thread and use that
thread as the message pump thread for the transparent form, then you will not
be tying up the main UI thread of your app when you resize. I think this may
work for you, try out something like the following:

private void btnShowForm_Cli ck(object sender, EventArgs e)
{
//Make sure only do this once. This thread is going to create the
//transparent form and be its message pump thread.
Thread t = new Thread(new ThreadStart(Cre ateOverlayForm) );
t.IsBackground = true;
t.Start();
}

//The form which is going to be transparent;
Form transparentForm = null;

void CreateOverlayFo rm()
{
//Create the transparent form
transparentForm = new Form();
transparentForm .Opacity = 0.1;

//Run the for on this thread creating a new message pump on the
//calling thread.
Application.Run (transparentFor m);
}

private void btnHideForm_Cli ck(object sender, EventArgs e)
{
//Only hide the form so we can reuse it later
HideTransparent Form();
}

private void HideTransparent Form()
{
//Make sure we call the hide method in the context of the thread
//that created the form.
if (this.transpare ntForm.InvokeRe quired)
{
this.transparen tForm.Invoke(ne w MethodInvoker(H ideTransparentF orm));
}
else
{
//This is the thread that created the form, safe to update
this.transparen tForm.Hide();
}
}
Hope that helps (or works :-))
Mark.
--
http://www.markdawson.org
"Ajith Menon" wrote:
Mark R. Dawson wrote:
What kind of degredation are you seeing? I set a form to 10% opacity and was
playing a video in my web browser, playing music with a visualization playing
and everything played fine while resizing the form, the CPU was at 100% but
that is okay. I was also running the app in debug mode, my laptop is not
great only 1.8GHz and 768MB of RAM.

Mark.

I have this transparent form within other application which has many
other forms. The other forms get dynamic data and gets updated
regularly. These other forms of the same application starts degrading
i.e. the dynamic data stop coming on it.

Nov 13 '06 #9
Thanks for the solution. I have not tried it yet ... but I think it
should work.
Will try it and get back to you.

Thankyou :-)

Regards,
Ajith

Nov 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3760
by: Dathon | last post by:
I have a Windows service that's built with .NET. The process is meant to run in the background and not suck up too much CPU time. I set the thread priority for the various threads in the service to Below Normal, but I'm still getting reports that the service is making a noticable impact on overall machine performance. I stuck some Thread.Sleep calls in a various places in the code, but that doesn't help much, since the service makes...
3
1570
by: GoCMS | last post by:
Sorry about this newbie question. I added a few tabbed pages into windows form. How can I make tabbed pages to resizable according to the window itself? Now it's like when i resize the window, the tabbed page keeps the absolute position and size. Thanks!
0
1061
by: dtp | last post by:
This one has got me stumped. Is there a way to figure out the utilization of each processor in an MP system? (2P and above) Right now I use the NtQuerySystemInformation API to get busy and idle time of each processor in a system and this works most of the time except on 64-bit Windows 2003 server on some platforms. What makes me nervous is MS says it may drop support for this call in future OSes so I can't depend on it long term...
0
1069
by: Peter | last post by:
When my form loads I have 3 items perfectly aligned: '________________________________________________________ (Width, Height) Startup form name is "strForm" (w800, h570) Location(0, 0) Picture Box control = "picBackGround" (w800, h570) Location (picBackGround) Group Box Control gbBox(w330, h256) Location (38, 72) I have also written this code to rescale the Picturebox on form
3
16173
by: BrianDH | last post by:
Hi I have a windows form and with init I have a tab control. How can I get the tab control to resize, Min/Max as the windows form is resized? Thanks
2
3964
by: timnels | last post by:
I have been able to execute Notepad.exe in a Panel (set to Dock.Fill) on a Windows Form, like: ProcessStartInfo psi = new ProcessStartInfo("notepad"); p = Process.Start(psi); p.WaitForInputIdle(); SetParent(p.MainWindowHandle, uiAppPanel.Handle); ShowWindow(p.MainWindowHandle, (int)ShowCommands.SW_MAXIMIZE); int style = GetWindowLong(p.MainWindowHandle, GWL_STYLE); SetWindowLong(p.MainWindowHandle, GWL_STYLE, style & ~WS_CAPTION);
2
1785
by: Emre Sevinc | last post by:
Hello, I have a strange situation. I create a very simple Windows Forms application and place the code below however even though I place breakpoints in various event handling points VS.NET 2005 only enters the breakpoint for the button but not for the form. Am I missing something? Why don't the events for my form Form1 have any effect? Form1.cs:
0
2251
by: PRR | last post by:
with WMI class Win32_Process i can get most details of Processes running one Pc.. except CPU utilization... THe class for CPU utilization u need to use Win32_PerfFormattedData_PerfProc_Process However it doesnt work in Windows XP... i wanna know wat class to use to get CPU utilization in win xp... also Processid is to be compared to get CPU utilization for Process to get info from both classes?
1
6630
by: Kaheru | last post by:
memory utilization increase? This is because when i try to keep track of the CPU utilization and memory utilization of my FTP server process (ftpserver.exe), the CPU utilization increase, but the memory utilization decrease. Why is this happening? PS: CPU Utilization is taken from Process\% Processor Time Memory Utilization is taken from Process\Working Set (I want to measure the physical memory it uses) Any help is appreciated....
0
10214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10048
jinu1996
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...
0
9865
tracyyun
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...
0
8872
agi2029
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...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.