|
Hi,
I have an application which gets info about system (for example running applications, processes, services, CPU info, OS info, ...). I create ProgressBar which will shows CPU usage (using WMI class to get actual usage). Then I create Timer (System.Windows.Forms.Timer) and set tick interval to one second. To get CPU usage and refresh ProgressBar to current usage value results to flicking in ListViews, when user wants to move with ScrollBar. Because of flicking I decided to create special thread for getting CPU usage and ProgressBar refresh to eliminate flicking. I create a new thread in constructor:
<br />
Thread threadRefresh = new Thread(new ThreadStart(Updating));<br />
threadRefresh.Start();<br />
which calls Updating method:
<br />
private void Updating() {<br />
refreshTimer.Tick += new EventHandler(RefreshCPUUsage);<br />
refreshTimer.Interval = 1000;<br />
refreshTimer.Start();<br />
}<br />
Method RefreshCPUUsage finally refresh ProgressBar:
<br />
private void RefreshCPUUsage(Object myObject, EventArgs myEventArgs) {<br />
manClass = new ManagementClass("Win32_PerfFormattedData_PerfOS_Processor");<br />
manObjectCollection = manClass.GetInstances();<br />
<br />
foreach (ManagementObject CPU in manObjectCollection) {<br />
progressBarCPU.Value = (int)Convert.ToUInt64(CPU.GetPropertyValue("PercentProcessorTime"));<br />
progressBarCPU.PerformStep();<br />
labelCPUPercent.Text = CPU.GetPropertyValue("PercentProcessorTime").ToString() + " %";<br />
}<br />
}<br />
This solution doesn't work, so I tried to do other based on System.Threading.Timer and Tread pool. In constructor:
<br />
WaitCallback myThreadMethod = new WaitCallback(Updating);<br />
ThreadPool.QueueUserWorkItem(myThreadMethod);<br />
Updating method:
<br />
private void Updating(Object stateInfo) {<br />
refreshTimer.Interval = 1000;<br />
refreshTimer.Elapsed += new ElapsedEventHandler(RefreshCPUUsage);<br />
refreshTimer.Start();<br />
}<br />
This is working but flickering in ListViews remains. I think that special thread for timer and refreshing can dispose flickering but it fails. Probably I'm doing somewhere mistake, but I don't know where. Please help me.
|
|
|
|
|
The problem isn't with the thread, its with the painting of the control.
You can problably set the DoubleBuffer property to true to alleviate this.
If it doesn't, then Look at your paint event.
Inside this event you probably have a method that is called that isnt returned immediately thus, cause the flicker.
Find a way to call it at some other point in time.
If your still stuck, then try exctending the List view and override the OnPaintBackground method. This redraws the control background. Warning tho. If you dont redraw the background you will see whats behind the control you dont paint that pixel.
The reason you see flicker is because of this>
The control calls OnPaintBackground. It then paints the control white or whatever the back color is
Then it calls your paint event. If the time it takes between the PaintBackground and end of the paint event. Then your eye perceives this as flicker.
Good luck
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
I have tried to use DoubleBuffer, but flickering remains. The area of ListView is not flickering but when Timer tick event occur and user is moving with scrollbar at that time, then scrollbar stops for a while and then continue in scrolling (lonely ListView is not redrawing or doing anything else). It seems that getting actual CPU usage info is demanding and because of that I tried to create special thread for timer and CPU usage info.
"Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing."
|
|
|
|
|
Have you tried calling Invalidate() and/or Application.DoEvents();
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Yes I tried both, but problem remains. I don't need to redraw or repaint whole area of ListView but only to stop scraping of ScrollBar when refreshing occur.
=================================================
"Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing."
Dick Brandon
|
|
|
|
|
I have created a method
public MyMethod( T myType ){}
But, it says T is not recognized.
Which namespace and Dll must I include to get T into my project ( Generics )
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
hi
try this:
using System.Collections.Generic;
|
|
|
|
|
I have this
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Collections;
using System.Runtime.Serialization;
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Is that method in a generic class? If not, T won't be recognized, no matter what namespaces you include (unless you actually were to create a type named T).
|
|
|
|
|
k, thanks.
thats the problem
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
T is the name of the generic template. However, it doesn't know that because you've not told it that T is a generic template, so it treats it as a real type. Since you don't have a type called T it causes an error
Ista wrote: public MyMethod( T myType ){}
Also, this is not the code you have - This code won't compile for reasons other than those you've specified.
public void MyMethod<T>(T myType){}
or
public class MyClass<T>
{
public void MyMethod(T myType) {}
}
|
|
|
|
|
Hi guys,
I need some help please, I am a newbie with C# and I am stuck on something.
I am using dataset to get data from the database, here is some bits of my code
SqlDataAdapter adp= new SqlDataAdapter();
DataSet ds=new DataSet();
adp.Fill(ds,"tbACJE");
if(ds.Tables["tbACJE"].Rows.Count>1)
{
System.Data.DataRow rd= ds.Tables["tbACJE"].Rows[0];
Double fTemp= 0.0;
fTemp=double.Parse(ds.Tables["tbACJE"].Compute("SUM(rd[0] + rd[1])", "").ToString());
What I am trying to do is
1) if there are more than 1 rows get the sum of the first 2 columns and if it's zero than Message and if not zero than get the difference amount.
Please help???
sasa
|
|
|
|
|
Hi
I'm using function in a dll written in C++ / MFC Visual Studio 6.
This use to work fine in the .NET framework 1.1, but I upgraded to Visual Studio 2005 and when I use any function from the dll I get a message 'LoaderLock was detected'. Are there any work around without changing the API?
Cheers Johan
|
|
|
|
|
What does that Dll do exactly?
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
|
GOD BLESS U
Hai
Difference betweeen .Dll and .exe files in .netplease give atleast 6 to 10 diferences)
thank u 4 ur kind support
bye 4 now
arun
|
|
|
|
|
Are writing a test? It sounds very much like that.
In that case, shame on you for trying to fool people into helping you passing a test that you don't have sufficient knowledge to pass on your own.
---
b { font-weight: normal; }
|
|
|
|
|
a dll file has an extension of ".DLL" and an exe has an extension of ".EXE"
Xorry, couldn't resist
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Hey, that's clever!
But could we imagine a dll with the extension .exe and vice-versa?
hehe...
sorry, I couldn't resist either!
|
|
|
|
|
Hello,
How can I make a search that do not only find the exact match but also similiar matches with xpath ?
For example,
our xml fragment is -lets say- like this :
<br />
<ROOT><br />
<DATA attribute1 = "123" attribute2 = "987"><br />
<AA> something here </AA><br />
<AB> again something here </AB><br />
</DATA><br />
<DATA attribute1 = "abc" attribute2 = "def"><br />
<BA> 123 </BA><br />
<BB> 987 </BB><br />
</DATA><br />
</ROOT><br />
..and I want to make a search to find all DATA's that contains the string "23" anywhere (at its attributes, childs, childs' attributes etc.
So after my search I will find the first DATA element (because its attribut1 is 123 and this contains 23) and also the second DATA element (because its BA child's value is 123 which contains 23).
Can I do this using xpath (I haven't find any SQL like "like" method under xpath) or may I choose another strategy?
.:: Something is Wrong ::.
|
|
|
|
|
You Must Load Youre Data To dataset Or dataView and then Search with Youre Cretria ;
MHF
|
|
|
|
|
may I use sql like select statements and complex queries in this dataset ?
also how can I acces element attributes through this dataset
.:: Something is Wrong ::.
|
|
|
|
|
DataTable Have Select Method You can use it
But for Complex Queries you must write a class or function that use that
Search in the internet mybe Find some codes
MHF
-- modified at 10:13 Tuesday 15th August, 2006
|
|
|
|
|
pashje wrote: Can I do this using xpath (I haven't find any SQL like "like" method under xpath) or may I choose another strategy?
yes you should
XmlDocument doc = new XmlDocument()
doc.Load(filename);
XmlNodeList list = doc.SelectNodes("//DATA@[your argusments here]");
I suggest grabbing the old book "XML in a nutshell". You need to know a few commands for xpath to get this to work.
Then just to a foreach on the XmlNodeList
foreach(XmlNode node in list){}
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
contains would be the most useful function in this case
XmlNodeList list = doc.SelectNodes("//DATA[contains(.,'123')]");
only two letters away from being an asset
|
|
|
|