|
No one has time to read all the details and find your problem.
It would be appropriate if you just tell us your problem in brief.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Hey Guys
a few days ago i made a custom control that uses GDI+.
after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work
and Memory Keep Leaking ... after that the text is moving very slow and so on...
Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ScreenerViewer.BL.NewsBar;
namespace ScreenerViewer
{
public partial class NewsBar : Control
{
Timer t = new Timer();
int Position;
StringWriter SdisplayNormalMode = null;
StringWriter SdisplayFlickerMode = null;
string sSeparatesign = " * ";
bool bRestPosition = false;
Brush Backroundbrush = Brushes.Red;
Brush BackroundFlickBrush = Brushes.Yellow;
Brush FontFlickerBrush =Brushes.Red;
int iColorChange = 0;
bool bFirstRun = false;
Font TextFont = new Font(new FontFamily("arial"), 60);
PointF TextPoint = new PointF();
private bool _bFilckerMode;
public bool bFilckerMode
{
get { return _bFilckerMode; }
set { _bFilckerMode = value; }
}
public NewsBar()
{
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
SdisplayNormalMode = new StringWriter();
t.Interval = 10;
t.Enabled = true;
t.Tick += new EventHandler(t_Tick);
Position = 0;
bFirstRun = true;
}
void t_Tick(object sender, EventArgs e)
{
Position+=2;
Invalidate();
}
protected override void OnPaint(PaintEventArgs pe)
{
if (!this.bFilckerMode)
{
pe.Graphics.FillRectangle(Backroundbrush,0,0,this.ClientSize.Width,ClientSize.Height);
SizeF stringSize = pe.Graphics.MeasureString(SdisplayNormalMode.ToString(),TextFont);
if (Position > ClientSize.Width)
{
Position =Convert.ToInt32( -1 * stringSize.Width);
}
if (Position == 0 && bFirstRun)
{
Position = Convert.ToInt32(-1 * stringSize.Width);
}
TextPoint.X = Position;
TextPoint.Y = 0;
pe.Graphics.DrawString(SdisplayNormalMode.ToString(), TextFont, Brushes.White, TextPoint);
}
else
{
if (iColorChange==20)
{
if (BackroundFlickBrush == Brushes.Yellow)
{
BackroundFlickBrush = Brushes.Red;
FontFlickerBrush = Brushes.Yellow;
}
else
{
BackroundFlickBrush = Brushes.Yellow;
FontFlickerBrush = Brushes.Red;
}
iColorChange = 0;
}
iColorChange++;
pe.Graphics.FillRectangle(BackroundFlickBrush, 0, 0, this.ClientSize.Width, ClientSize.Height);
SizeF stringSize = pe.Graphics.MeasureString(SdisplayFlickerMode.ToString(), TextFont);
if (Position == 0&&bFirstRun)
{
Position = Convert.ToInt32(-1 * stringSize.Width);
}
if (Position > ClientSize.Width)
{
Position = Convert.ToInt32(-1 * stringSize.Width);
bFilckerMode = false;
}
if (bRestPosition)
{
Position = Convert.ToInt32(-1 * stringSize.Width);
}
bRestPosition = false;
pe.Graphics.DrawString(SdisplayFlickerMode.ToString(), TextFont, FontFlickerBrush, TextPoint);
if (!bFilckerMode)
{
SdisplayFlickerMode = null;
}
}
bFirstRun = true;
base.OnPaint(pe);
}
public void DisplayListNormalMode(string[] Smsgdisplay)
{
if (Smsgdisplay.Length > 0)
{
foreach (string msg in Smsgdisplay)
{
SdisplayNormalMode.Write(msg + sSeparatesign);
}
}
}
public void DisplayListFlickerMode(BL.NewsBar.Flickeritem[] SFdisplay)
{
SdisplayFlickerMode = new StringWriter();
this.bFilckerMode = true;
bRestPosition = true;
string[] SoundFiles=null;
if (SFdisplay.Length > 0 )
{
SoundFiles= new string[SFdisplay.Length];
int index=0;
foreach (Flickeritem msg in SFdisplay)
{
SdisplayFlickerMode.Write(msg.Msg + sSeparatesign);
SoundFiles[index]=msg.SoundPath;
index++;
}
}
PlaySound sound = new PlaySound(SoundFiles);
sound.PlayMyList();
}
}
}
|
|
|
|
|
michael@cohen wrote: after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work
and Memory Keep Leaking ... after that the text is moving very slow and so on...
michael@cohen wrote: t.Interval = 10;
Do the math. 100 repaints a second! 15 frames a second will be more than enough.
|
|
|
|
|
I can't beleive you rabbited through all that code or did the interval issues jump out!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: did the interval issues jump out!
Mostly, did do a quick scan to see if he was wasting resources, but that was not the case.
|
|
|
|
|
thanx for checking the code.
ill try to do as you say...
|
|
|
|
|
I have created a widows service,register it and it is working fine.
Now i have created Windows application.RIght Click the solution and click add new item.I have added windows service compiled code and register using "installutil C:\mcWebService\bin\Debug\windowsapplication1.exe"
Now when i go to computer->manage->services and start service it gives following error
"Error: 1053 the service did not respond to the start or control request in timly fashion"
any body has solution for this
PIEBALDconsult answered me on this forum that installutil is for windows services not for windows application.Thanks for this reply but i want to know that in windows application when we right click on project and click on "Add new item".FRom here we can add windows service class .Now my question is how this added windows service class can be installed and run?
|
|
|
|
|
idreesbadshah wrote: windows service class can be installed and run
This is done using installutil. You cannot mix a windows application and a windows service in a single install.
Check out BOL for deployment, or Google for deploying .net applcations.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Thanks for your Replly
Just tell me one thing more.If we cannot mix windows apllication and windows services then why .net allow us in windows application to right click project and add windows service class.WHats it use there ifwe donot mix them.
|
|
|
|
|
idreesbadshah wrote: why .net allow us in windows application to right click project and add windows service class.WHats it use there ifwe donot mix them.
I assume Microsoft expected people to have a little understanding of the about what they are doing. You can do all sorts of things in programming, just like life, and just because you CAN do something it doen't mean you SHOULD do it - you can put your fingers in a chainsaw, it doesn't mean to say you should.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hello everyone,
My C# application is built for "Any CPU" option using .Net framework 2.0 using Visual Studio 2008, and I run it on a machine which is Winsows Server 2003, x64. I installed,
- .Net Framework 32-bit version 2, 3, and 3.5;
- .Net Framework 64-bit version 2, 3, and 3.5.
My question is, when run the application on the specific machine, which version of .Net Framework will be used? And why (what is the rule to choose)?
thanks in advance,
George
|
|
|
|
|
The framework depends on the OS that is on the server.So if there is X64 OS then framework would be 64 bit and same will be used by the application
Cheers!!
Brij
|
|
|
|
|
|
I believe 64 bit framework will be used if you are on a 64 bit machine. I am not sure though.
|
|
|
|
|
Thanks N a v a n e e t h,
The machine run the code is server 2003 (x64) and the build machine make the binary "Any CPU", not specifying x64 in build option, and when making the build version 2.0 CLR is used.
1.
In this situation, you mean 64-bit framework is always used?
2.
Which version of CLR is used on the machine? 2.0? 3.0 or 3.5?
regards,
George
|
|
|
|
|
if you are system is Win2k3 , X64 your .NET will used only 64 bit version of Framework.
if you want to run the application on x64 bit system its need .NET Framework 64 bit OS , but i think it will not run on 32 Bit System.
|
|
|
|
|
|
If you are running on a 64-bit OS and are compiled under the "Any CPU" option it should choose the 64-bit Fx if available. Since you specifically said you compiled targeting the Fx 2.0 your application will run against that version by default unless it is a Windows service, in which case it will run against the latest version of the Fx that is installed.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hi Scott,
Sorry it is a Windows service -- so it will run under CLR 3.5?
How to check which version of CLR a process is using?
regards,
George
|
|
|
|
|
Yes, a windows service will, by default, run using the latest available Fx version (in this case Fx 3.5) [A minor correction, the CLR version from Fx 2.0 on is still CLR version 2.0.]
From inside the process you can access the Environment.Version[^], which will return the version number of the CLR you are running under (not the Framework).
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Scott Dorman wrote: Yes, a windows service will, by default, run using the latest available Fx version
This is a new info for me. Even the service is targeted to framework 2.0, it takes the latest version ? Is there any documents to prove this ?
|
|
|
|
|
I am also asking this.
regards,
George
|
|
|
|
|
I haven't been able to find the documentation I saw this in, but it has to do with the way certain unmanaged applications (like IIS, SQL, DLLHost, etc.) actually host an instance of the .NET runtime. I'm still looking, so if I find the information I'll update the post.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Thanks Scott,
1. If in my process, I have not added any code to retrieve Environment.Version, how could I retrieve the CLR version it is using?
2. "A minor correction, the CLR version from Fx 2.0 on is still CLR version 2.0." -- I am confused. Sorry English is not my native language, do you mean .Net Framework 2.0 and CLR 2.0 are the same thing?
regards,
George
|
|
|
|
|
1 - You have to add and re-deploy your application.
George_George wrote: .Net Framework 2.0 and CLR 2.0 are the same thing?
They are not the same. One is a set of classes and other one is "Common language runtime". He meant .NET Framework 3.5 uses CLR version 2.0.
|
|
|
|