• 大小: 21KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: C#
  • 标签: c#  vs2010  

资源简介

c#仿Windows任务管理器,显示应用程序,进程,性能(CPU使用情况、内存使用情况、硬盘所用及剩余空间)

资源截图

代码片段和文件信息

using System;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
///Download by http://www.newxing.com

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))

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1162  2007-03-29 09:08  www.NewXing.com\Test\Properties\AssemblyInfo.cs

     文件       1321  2007-03-29 09:04  www.NewXing.com\SystemInfo\Properties\AssemblyInfo.cs

     文件      14965  2010-11-12 01:07  www.NewXing.com\SystemInfo\CustomtMarshaler.cs

     文件        947  2010-11-12 01:07  www.NewXing.com\SystemInfo\DiskInfo.cs

     文件       8826  2007-03-29 15:58  www.NewXing.com\Test\frmProcess.cs

     文件      26464  2007-03-29 15:58  www.NewXing.com\Test\frmProcess.designer.cs

     文件        924  2010-11-12 01:07  www.NewXing.com\SystemInfo\IpInfo.cs

     文件       4181  2007-03-29 09:11  www.NewXing.com\Test\LineChart.cs

     文件       1599  2007-03-29 09:12  www.NewXing.com\Test\LineChart.Designer.cs

     文件       2039  2010-11-12 01:07  www.NewXing.com\SystemInfo\MIB_IFROW.cs

     文件        596  2010-11-12 01:07  www.NewXing.com\SystemInfo\MIB_IFTABLE.cs

     文件       3464  2010-11-12 01:07  www.NewXing.com\SystemInfo\NetInfo.cs

     文件       1559  2010-11-12 01:07  www.NewXing.com\SystemInfo\ProcessInfo.cs

     文件        468  2007-03-29 09:14  www.NewXing.com\Test\Program.cs

     文件       2862  2007-03-29 09:08  www.NewXing.com\Test\Properties\Resources.Designer.cs

     文件       1087  2007-03-29 09:08  www.NewXing.com\Test\Properties\Settings.Designer.cs

     文件      17348  2010-11-12 01:08  www.NewXing.com\SystemInfo\SystemInfo.cs

     文件       2299  2007-03-29 09:09  www.NewXing.com\SystemInfo\SystemInfo.csproj

     文件       3816  2007-03-29 15:57  www.NewXing.com\Test\Test.csproj

     文件       6774  2007-03-29 15:58  www.NewXing.com\Test\frmProcess.resx

     文件       5814  2007-01-08 17:21  www.NewXing.com\Test\LineChart.resx

     文件       5612  2007-03-29 09:08  www.NewXing.com\Test\Properties\Resources.resx

     文件        249  2007-03-29 09:08  www.NewXing.com\Test\Properties\Settings.settings

     文件       1385  2007-03-29 09:09  www.NewXing.com\SystemInfo.sln

    ..A..H.     24064  2007-04-11 09:18  www.NewXing.com\SystemInfo.suo

     目录          0  2007-04-06 15:59  www.NewXing.com\SystemInfo\Properties

     目录          0  2007-04-06 15:59  www.NewXing.com\Test\Properties

     目录          0  2007-04-06 15:59  www.NewXing.com\bin

     目录          0  2007-04-06 15:59  www.NewXing.com\SystemInfo

     目录          0  2007-04-06 15:59  www.NewXing.com\Test

............此处省略3个文件信息

评论

共有 条评论