59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Tor
|
|
{
|
|
public class Utility
|
|
{
|
|
private Utility()
|
|
{
|
|
}
|
|
public static String FormatNumber(double number,int places,bool commas=false)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
StringBuilder formatString=new StringBuilder();
|
|
if (commas&&number>=1000.00) formatString.Append("{0:0,0.");
|
|
else formatString.Append("{0:0.");
|
|
for(int index=0;index<places;index++)formatString.Append("0");
|
|
formatString.Append("}");
|
|
if (double.NaN.Equals(number)) sb.Append("N/A");
|
|
else sb.Append(String.Format(formatString.ToString(), number));
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static String ThreadStateToString(Thread thread)
|
|
{
|
|
switch(thread.ThreadState)
|
|
{
|
|
case ThreadState.Running :
|
|
return "Running";
|
|
case ThreadState.StopRequested :
|
|
return "StopRequested";
|
|
case ThreadState.SuspendRequested :
|
|
return "SuspendRequested";
|
|
case ThreadState.Background :
|
|
return "Background";
|
|
case ThreadState.Unstarted :
|
|
return "Unstarted";
|
|
case ThreadState.Stopped :
|
|
return "Stopped";
|
|
case ThreadState.WaitSleepJoin :
|
|
return "WaitSleepJoin";
|
|
case ThreadState.Suspended :
|
|
return "Suspended";
|
|
case ThreadState.AbortRequested :
|
|
return "AbortRequested";
|
|
case ThreadState.Aborted :
|
|
return "Aborted";
|
|
default :
|
|
return "Unknown";
|
|
}
|
|
}
|
|
}
|
|
}
|