自學C#多執行緒Thread的應用
WMI是英文Windows Management Instrumentation的簡寫,它的功能主要是:訪問本地主機的一些資訊和服務,可以管理遠端計算機(當然你必須要擁有足夠的許可權),比如:重啟,關機,關閉程序,建立程序等。
當然此文是適用於vbscript
微軟官方的資料:
例項如下:
用WMI,先工程-引用 Microsoft WMI Scripting V1.1 Library
獲取顯示卡/音效卡/記憶體/作業系統的資訊
分享了C#多執行緒Thread使用的示例程式碼基本使用示例:
using
System;
using
System.Threading;
namespace
month_9_10._1009
{
class
Run5
{
/* 測試執行緒的呼叫過程
* 主執行緒輸出world,子執行緒輸出hello
*/
public
static
void
showHello()
{
for
(
int
i = 0; i < 100; i++)
{
Console.WriteLine($
"Hello\t#{Thread.CurrentThread.Name}"
);
}
}
public
static
void
Main(
string
[] args)
{
Thread.CurrentThread.Name =
"Main Thread!"
;
var childThreadRef =
new
ThreadStart(showHello);
Console.WriteLine(
"This is Main process!!!"
);
var childThread =
new
Thread(childThreadRef);
childThread.Name =
"Child Thread!"
;
childThread.Start();
for
(
int
i = 0; i < 100; i++)
{
Console.WriteLine($
"World!\t#{Thread.CurrentThread.Name}"
);
}
}
}
}
執行緒生命週期狀態圖,C#執行緒優先順序。
硬體類
Computer System Hardware Classes
he Cooling Devices subcategory groups classes that represent instrumentable fans, temperature
Class Description
Win32_Fan Represents the properties of a fan device in the computer system.
Win32_HeatPipe Represents the properties of a heat pipe cooling device.
Win32_Refrigeration Represents the properties of a refrigeration device.
Win32_TemperatureProbe Represents the properties of a temperature sensor (electronic thermometer).
Input Device Classes
The Input Devices subcategory groups classes that represent keyboards and pointing devices.
Class Description
Win32_Keyboard Represents a keyboard installed on a Windows system.
例項三:執行緒同步(售票模擬)
using
System;
using
System.Drawing;
using
System.Threading;
using
System.Windows.Forms;
namespace
RollMove
{
public
partial
class
Form1 : Form
{
Thread th1 =
null
;
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
int
_sx = 40;
int
_ex = 280;
int
_top = 70;
th1 =
new
Thread(() => {
while
(
true
)
{
if
(_sx <= _ex)
{
_ex = 280;
label1.Location =
new
Point(_sx, _top);
Thread.Sleep(20);
_sx += 5;
}
else
{
_ex = 40;
label1.Location =
new
Point(_sx, _top);
Thread.Sleep(20);
_sx -= 5;
}
}
});
th1.Start();
}
private
void
Form1_FormClosed(
object
sender, FormClosedEventArgs e)
{
if
(th1!=
null
)
{
th1.Abort();
}
}
}
}
可以找到,其中也還有部分示例程式碼
簡單Win_32類表
Win32 Classes
Microsoft&reg; Windows&reg; classes give you the means to manipulate a variety of objects. The following table identifies the categories of Windows classes.
Category Description
Computer system hardware Classes that represent hardware related objects.
Operating system Classes that represent operating system related objects.
Installed applications Classes that represent software related objects.
WMI service management Classes used to manage WMI.
Performance counters Classes that represent formatted and raw performance data.
自學C#多執行緒Thread的應用
快速開發量化機器人軟體,量化交易機器人APP系統搭建,諮詢熱線:17154957219