資源簡介
c#編寫的任務(wù)管理器,用于獲取系統(tǒng)中的內(nèi)存信息,CPU信息,進(jìn)程的運(yùn)行情況等
代碼片段和文件信息
using?System;
using?System.IO;
using?System.Collections;
using?System.Reflection;
using?System.Runtime.InteropServices;
using?System.Threading;
namespace?Lemony.SystemInfo
{
///?
///?CustomMarshaler?class?implementation.
///?
public?abstract?class?CustomMarshaler
{
#region?Fields
//?The?internal?buffer
internal?byte[]?data;
private?MemoryStream?stream;
private?BinaryReader?binReader;
private?BinaryWriter?binWriter;
#endregion
#region?constructors
public?CustomMarshaler()
{
}
#endregion
#region?public?methods
public?void?Deserialize()
{
if?(data?!=?null)
{
if?(binReader?!=?null)
{
binReader.Close();
stream.Close();
}
//?Create?a?steam?from?byte?array
stream?=?new?MemoryStream(data);
binReader?=?new?BinaryReader(stream?System.Text.Encoding.Unicode);
ReadFromStream(binReader);
binReader.Close();
}
}
public?void?Serialize()
{
if?(data?!=?null)
{
stream?=?new?MemoryStream(data);
binWriter?=?new?BinaryWriter(stream?System.Text.Encoding.Unicode);
WriteToStream(binWriter);
binWriter.Close();
}
}
public?int?GetSize()
{
int?size?=?0;
FieldInfo[]?fields?=?this.GetType().GetFields(BindingFlags.Public?|?BindingFlags.Instance);
foreach?(FieldInfo?field?in?fields?)
{
if?(field.FieldType.IsArray)
{
size?+=?GetFieldSize(field);
}
else?if?(field.FieldType?==?typeof(string))
{
size?+=?GetFieldSize(field)*2;
}?
else?if?(field.FieldType.IsPrimitive)
{
size?+=?Marshal.SizeOf(field.FieldType);
}
}
return?size;
}
#endregion
#region?properties
public?byte[]?ByteArray
{
get
{
return?data;
}
}
#endregion
#region?virtual?and?protected?methods
public?virtual?void?ReadFromStream(BinaryReader?reader)
{
object[]?param?=?null;
//?Get?all?public?fields
FieldInfo[]?fields?=?this.GetType().GetFields(BindingFlags.Public?|?BindingFlags.Instance);
//?Loop?through?the?fields
foreach(FieldInfo?field?in?fields)
{
//?Retrieve?the?read?method?from?ReadMethods?hashtable
MethodInfo?method?=?(MethodInfo)MarshallingMethods.ReadMethods[field.FieldType];
if?(field.FieldType.IsArray)
{
Type?element?=?field.FieldType.GetElementType();
if?(element.IsValueType?&&?element.IsPrimitive)
{
if?((element?==?typeof(char))?||?element?==?typeof(byte))
{ ?
param?=?new?object[1];
param[0]?=?GetFieldSize(field);
field.SetValue(this?method.Invoke(reader?param));?
}
else?//?any?other?value?type?array
{
param?=?new?object[2];
param[0]?=?reader;
param[1]?=?GetFieldSize(field);
field.SetValue(this?method.Invoke(null?param));?
}
}
else?//?array
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????36864??2009-08-19?14:36??SystemInfo1\bin\Lemony.SystemInfo.dll
?????文件??????65024??2009-08-19?14:36??SystemInfo1\bin\Lemony.SystemInfo.pdb
?????文件??????36864??2009-08-19?14:36??SystemInfo1\bin\Test.exe
?????文件??????38400??2009-08-19?14:36??SystemInfo1\bin\Test.pdb
?????文件???????5632??2005-12-08?14:51??SystemInfo1\bin\Test.vshost.exe
?????文件??????36864??2009-08-19?14:36??SystemInfo1\SystemInfo\bin\Lemony.SystemInfo.dll
?????文件??????65024??2009-08-19?14:36??SystemInfo1\SystemInfo\bin\Lemony.SystemInfo.pdb
?????文件??????36864??2009-08-19?14:36??SystemInfo1\SystemInfo\bin\Test.exe
?????文件??????38400??2009-08-19?14:36??SystemInfo1\SystemInfo\bin\Test.pdb
?????文件???????5632??2005-12-08?14:51??SystemInfo1\SystemInfo\bin\Test.vshost.exe
?????文件??????14926??2007-03-29?09:06??SystemInfo1\SystemInfo\CustomtMarshaler.cs
?????文件????????908??2007-03-29?09:06??SystemInfo1\SystemInfo\DiskInfo.cs
?????文件????????885??2007-03-29?09:06??SystemInfo1\SystemInfo\IpInfo.cs
?????文件???????2000??2007-03-29?09:07??SystemInfo1\SystemInfo\MIB_IFROW.cs
?????文件????????557??2007-03-29?09:07??SystemInfo1\SystemInfo\MIB_IFTABLE.cs
?????文件???????3427??2007-03-29?09:07??SystemInfo1\SystemInfo\NetInfo.cs
?????文件??????36864??2009-08-19?14:36??SystemInfo1\SystemInfo\obj\Debug\Lemony.SystemInfo.dll
?????文件??????65024??2009-08-19?14:36??SystemInfo1\SystemInfo\obj\Debug\Lemony.SystemInfo.pdb
?????文件????????168??2009-08-19?14:37??SystemInfo1\SystemInfo\obj\SystemInfo.csproj.FileList.txt
?????文件???????1519??2007-03-29?09:07??SystemInfo1\SystemInfo\ProcessInfo.cs
?????文件???????1321??2007-03-29?09:04??SystemInfo1\SystemInfo\Properties\AssemblyInfo.cs
?????文件??????14926??2007-03-29?09:06??SystemInfo1\SystemInfo\SystemInfo\CustomtMarshaler.cs
?????文件????????908??2007-03-29?09:06??SystemInfo1\SystemInfo\SystemInfo\DiskInfo.cs
?????文件????????885??2007-03-29?09:06??SystemInfo1\SystemInfo\SystemInfo\IpInfo.cs
?????文件???????2000??2007-03-29?09:07??SystemInfo1\SystemInfo\SystemInfo\MIB_IFROW.cs
?????文件????????557??2007-03-29?09:07??SystemInfo1\SystemInfo\SystemInfo\MIB_IFTABLE.cs
?????文件???????3427??2007-03-29?09:07??SystemInfo1\SystemInfo\SystemInfo\NetInfo.cs
?????文件??????36864??2009-08-19?14:36??SystemInfo1\SystemInfo\SystemInfo\obj\Debug\Lemony.SystemInfo.dll
?????文件??????65024??2009-08-19?14:36??SystemInfo1\SystemInfo\SystemInfo\obj\Debug\Lemony.SystemInfo.pdb
?????文件????????168??2009-08-19?14:37??SystemInfo1\SystemInfo\SystemInfo\obj\SystemInfo.csproj.FileList.txt
............此處省略78個(gè)文件信息
評論
共有 條評論