62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
/* This software is licensed by the MIT License, see LICENSE file */
|
|
/* Copyright © 2024-2025 Gregory Lirent */
|
|
|
|
using System.Text.Json.Serialization;
|
|
using WebmrAPI.Utils;
|
|
|
|
namespace WebmrAPI.Models
|
|
{
|
|
public class ProcessThreadInfo : ConcurrentObject
|
|
{
|
|
private TimeSpan _lastPTime = TimeSpan.Zero;
|
|
private TimeSpan _curPTime = TimeSpan.Zero;
|
|
private IEnumerable<BaseWindowInfo>? _windows;
|
|
|
|
private int _id = 0;
|
|
private int _currentPriority = 0;
|
|
private int _basePriority = 0;
|
|
private double _cpuUsage = 0;
|
|
|
|
[JsonIgnore]
|
|
public TimeSpan TotalProcessorTime
|
|
{
|
|
set { lock (_lock) { _lastPTime = _curPTime; _curPTime = value; } }
|
|
}
|
|
[JsonIgnore]
|
|
public double ProcessorTime
|
|
{
|
|
get { lock (_lock) return (_curPTime - _lastPTime).TotalMilliseconds; }
|
|
}
|
|
|
|
public int ID
|
|
{
|
|
get => LockedGet(ref _id);
|
|
set => LockedSet(ref _id, value);
|
|
}
|
|
|
|
public int CurrentPriority
|
|
{
|
|
get => LockedGet(ref _currentPriority);
|
|
set => LockedSet(ref _currentPriority, value);
|
|
}
|
|
|
|
public int BasePriority
|
|
{
|
|
get => LockedGet(ref _basePriority);
|
|
set => LockedSet(ref _basePriority, value);
|
|
}
|
|
public double CpuUsage
|
|
{
|
|
get => LockedGet(ref _cpuUsage);
|
|
set => LockedSet(ref _cpuUsage, value);
|
|
}
|
|
|
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
public IEnumerable<BaseWindowInfo>? Windows
|
|
{
|
|
get => LockedGet(ref _windows);
|
|
internal set => LockedSet(ref _windows, value);
|
|
}
|
|
}
|
|
}
|