|
thats a method and it should get the total cpu usage as described...
% Processor Time is the percentage of elapsed time that the processor
spends to execute a non-Idle thread. It is calculated by measuring the
duration of the idle thread is active in the sample interval, and
subtracting that time from interval duration. (Each processor has an idle
thread that consumes cycles when no other threads are ready to run). This
counter is the primary indicator of processor activity, and displays the
average percentage of busy time observed during the sample interval. It is
calculated by monitoring the time that the service is inactive, and
subtracting that value from 100%.
If you are comparing this to the task manager, it is pretty close....
I find that using the preformance counters I get close results, but often sporatic ones... probably cause i'm not using them right.
Check this class out, you will like it better...
CpuUsage[^]
/\ |_ E X E GG
|
|
|
|
|
I am a C# beginner. In VB/ASP i had developed an infrastructure that allowed recent trace/debug information to be kept in memory. It would be dumped to an error handler when exceptions were raised. Only the most recent trace entries would be retained. Is it possible to do the same with the .Net Trace class, or will i have to write my own code? From what i have read it seems that a Trace Listener can only be a stream, like writing to a disk file. This is useful, but i have other troubleshooring needs.
Thanks
|
|
|
|
|
Why develop it? It's already developed. If you have tracing enabled (<trace enabled="true"/> in your Web.config file - see the <trace> documentation in the .NET Framework SDK for more attributes), then just point your browser to approot/trace.axd, where approot is the root directory of your web application (not necessarily the root of your web server).
This collects object hierarchies (within the page), exceptions, trace messages (of course), query strings, form variables, HTTP headers, cookies, etc - most likely a lot more than you were tracking before.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
BTW, this is an ASP.NET question and belongs in the ASP.NET forum, regardless of what language you're using. It's important to understand that C# is one of about 30 languages that target the common language runtime, or CLR. I suggest reading through the .NET Framework SDK or picking up a good book (though nothing is as comprehensive as reading the class library documentation in the .NET Framework SDK).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your comments but there appears to be a misunderstanding here. Both VB and ASP had no tracing ability built-in to the product. This is why the infrastructure was created. I was singularly developing 100K+ lines of code. I only mentioned this as an example of what was done before and what i would like to do in C# applications. What i am trying to determine is whether the Net trace/debug classes can behave a certain way. I hope i described things clearly enough. In my reading of the Microsoft books and documentation, the behavior i seek is not clarified. I also found nothing in an internet search. So i appeal to the forums for more information before i tackle things by trial-and-error.
Thanks for the help
|
|
|
|
|
How does this apply to anything I said? For one, I answered your question in the first reply which is covered in the .NET Framework and I mentioned what all it outputs. In my second reply I was merely pointing out that you asked in the wrong forum - this belongs in the ASP.NET forum since it has absolutely nothing to do with C# because ASP.NET can be used by any managed language (i.e., you could write an MC++ assembly that the .aspx pages expose).
Asking for help in forums is not what I was saying you did wrong - only that it was posted in the wrong forum. Regardless, I hope my first reply was informative. The ASP.NET tracing does provide a lot of information - about everything you could think of - and is better to use then a home-grown solution since the tracing is built deep into ASP.NET. And yes, I am aware of a lack of tracing and what-not in ASP - I've been doing this long before ASP was even an idea.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a problem - i have a bunch of processes reading and writing to the disk. I simply want to know which files / directories this processes are accessing.
I tried using the FileSystemWatcher object - but i can only get which files, have been modified deleted, etc. I can get which process caused that change.
So I'm looking for something that when the file system receives a read request, it must be aware of which process is making the request - or something along these lines.
ideas?
|
|
|
|
|
It's possible to do, but hardly practical. You will need to write a file system driver that attaches filter objects to the O/S device objects. This driver can then expose an interface that your main application can use to get the information it wants.
You'll need to know about writing Windows NT kernel drivers, internal workings of Windows NT kernels, and, of course, the internals of NTFS.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
wowww - and i thought it would be pretty straightforward. thanks for giving me an idea of how complicated it would be.
thanks
|
|
|
|
|
Is there any possibility to save Bitmap as JPG, however
with better quality than allows the following code :
...
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,100);
foreach( ImageCodecInfo encoder in encoders ) //PERF OPT
{
if( encoder.MimeType == "image/jpeg" )
{
img.Save(stream,encoder,encoderParameters);
}
}
When saving images with maximum possible quality I get files that
are about 80% of size of image produced by Adobe Phooshop,
even with 10 (scale 1-12 ) quality (!)
It was somewhat about 160 kB, versus 200 kB, and of course,
the difference had been evident. The difference was visible
due to the fact that on the original image some lines and polygons
along with text were drawn. And these require quite a good
compression quality.
Sombody might say that I should save images as GIF or PNG, however
these do not provide as good compression ratio as JPEG does, even
when saving JPEG with the best quality (size increases)
(best JPEG by PhotoShop == 320 KB, best by framework == 160 KB,
PNG = 770 KB)
When saving image as JPEG with photoshop, user is able to choose
compression level (that seems to be "wider" than what framewotk
provides) and is able to choose from "Format options" that are
following: BaseLine, Baseline-Optimized and Progressive.
Is there any way to make the same work in GDI+ ?
But the main question remains : How to save image with quality
better than that from the above code example.
Thanks
Michał Januszczyk
|
|
|
|
|
The problem is the JPEG "compression". You don't get good compression with high quality. The JPEG format is well-known to not handle lines polygons with good quality. JPEG is for photographic type images where the "lossyness" can be hidden in the image. Your just not going to get high quality images without sacrificing compression with JPEG.
For the type of image that your talking about (lines and polygons) .GIF is a much better choice. But, it also has it's limitations, like limited color depth support.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
The problem is the JPEG "compression". You don't get good compression with high quality. The JPEG format is well-known to not handle lines polygons with good quality
Thank You.
Yes, i'm aware that JPEG will not do as good image as GIF would do here , but I would like simply to get as much as Photoshop gives, and this would sattisfy me really.
Let me say that again: I draw lines on background that is a photo. Savig whole image as GIF of PNG would produce enormously big image size, and savig as JPEG does not (currently) give appropriate quality. However Photoshop _is_ able to save as JPEG, with quality even beter than ramework does, and this quality is in my opinion good enough to save lines drawn on photo-background.
Michal
|
|
|
|
|
But as Dave said, so long as you compress a JPEG using most compression algorithms (which are lossy), you will loose quality. My recommendation is - much like you did for the quality encoder parameter - adjust the compression algorithm as well until you find a happy medium. Perhaps find out which compressional algorithm Photoshop is using (LZH, IIRC) and use the same.
Also keep in mind other properties Photoshop may be saving. Just looking at the file sizes may not be enough. By default, Photoshop will save ICC profiles with images and may embed other properties when possible (using EXIF with JPEG, it is possible). Unless the image sizes are large, an 80% margin isn't completely unbelievable (though it sure pushes it).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
My recommendation is - much like you did for the quality encoder parameter - adjust the compression algorithm as well until you find a happy medium. Perhaps find out which compressional algorithm Photoshop is using (LZH, IIRC) and use the same
I've investigated the matter, and it seems that whan saving image as JPEG, the only encoder paarameters that can be used are: Transformation and Quality. (As I noted before Quality when set even to maximum does not suit my needs). Compression encoder parameter is available only whan savig image as TIFF (available options are: none, LZW, Rle, CCIIT3, CCIIT4)
Thanks
Michał

|
|
|
|
|
does anybody have a link to a tutorial that is tried and tested and simple and accurate and etc. :P on how to use sockets in c#?
what i need to do is to connect to a specific ip on a certain port, send info and recieve and process it, then send more depending on what's been sent etc.
what type of connect is also best to use?
thanks.
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
There are several good ones here - use the ratings to see what people think is good.
As far as the protocol, that is defined entirely by you. Sockets are a simple connection between, well, sockets. That's it. More than likely, you'll want to use a TcpClient if you want to use TCP/IP for the connection protocol. What comes across the wire is defined by you, however.
Tons of protocols including HTTP, SMTP, FTP, etc. all use TCP/IP, but the protocol - the messages sent back and forth - is unique to each (though some common approaches exist, such as headers vs. body). In fact, someone earlier today simply asked about "telnet". Telnet is really just a simple TCP socket connection with know particular protocol.
A good way to handle this is to connect using a TcpClient and getting a NetworkStream by calling TcpClient.GetStream . Instantiate a StreamWriter and StreamReader on that stream with an agreed-upon encoding (like ASCII, UTF8, Unicode, etc.). Send and receive commands.
A good protocol will define errors codes that typically prefix a response message, making it quick and simple for you to determine if a command passed or failed.
For good examples of such protocols, I recommend you search http://www.ietf.org/rfc[^] for RFCs describing TCP protocols like SMTP, HTTP (pretty easy one), FTP, etc. I would recommend DICT (http://www.ietf.org/rfc/rfc2229.txt[^]), which I'm currently wrapping (slowly, with low priority). It's a simple protocol and gives you a pretty good idea of a good protocol design.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This article http://www.codeproject.com/csharp/pop3client.asp[^] will help a lot because it is simple, uses sockets to send and receive data with a pop3 server (which is cleartext)... exactly what you want.
The best part is, if you're just doing this to learn, you dont need to write the server piece!
Microsoft .NET - Come on! I need the Traffic!
|
|
|
|
|
make a little pop3 class to talk to your email server and read your messages etc. You coul make a class for all the pop commands like AUTH, LIST etc. Read the pop3 rfc, its very simple. I did something like this, and it was a fun way to learn .net sockets...
/\ |_ E X E GG
|
|
|
|
|
thanks all.
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
hi - is there a simple and good way to control the 9-pin serial port at the back of your computer? i would like to use it for some simple electronics commands and i need to be able to send a certain number of pules to it over a set time,- also how can you recieve?
i found this link on google, is it right? and what is i don't want to send a message to want to pulse it? any ideas?
cheers,
surgeproof
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
Simple? Not on your life...
You said your looking to send signal pulses? The article you found won't let you do that. That article deals with properly formatted serial communications. You're apparently looking at manipulating the serial port hardware directly and in very non-standard methods. Your going to have a DIFFICULT time with this one. Receiving data is going to be very difficult at best.
You might have better luck with using the parallel port for a project like this. Most of the same problems apply, but there is more documentation on this port than with serial. For example...[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I agree with Dave, what you're trying to do is pretty impossible.
Better to get hold of a development kit for a simple microcontroller (e.g. a Arizona Micro PIC device) that has an on-baord UART and talk to that via your PC serial port. The PIC can be programmed to generate your pulses, etc, depending on the instructions it gets via the serial port.
|
|
|
|
|
cheers both for your helpful responses. i will soon be getting more into PIC development, and i have a PIC programmer coming soon, so i may be able to figure out UART if i need it.
thanks for now,
surgeproof.
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
Hello,
If I want to manage all unhandled exceptions myself, do I have to subscribe to both the AppDomain.CurrentDomain.UnhandledException and Application.ThreadException events or would it be enough to just subscribe to the Application.ThreadException event?
Does the Application.ThreadException event handle all unhandled exceptions or does the UnhandledException event of the CurrentDomain handle some?
Thanx for the clarification
-Flack
|
|
|
|
|
They both allow you to handle unhandled exceptions, but handling the Application.ThreadException gives you a good chance to make sure your application remains stable. Unhandled exceptions that affect the message pump are potentially dangerous. For example, unhandled exceptions in certain places (like when a form is loading) will cause the 'X' button in your window to stop responding, along with others errors you might not notice right away.
Of course, if you're not using Windows Forms (say, a Console application) then handle the AppDomain.UnhandledException event.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|