我试图在C#中启动/停止基于Windows的集群,下面是我到目前为止使用的代码...当我到达下面的TakeOffLine函数时,我从System.Management.ManagementStatus得到一个"未找到"异常.未找到.不知道到底发现了什么?如果有(替代)更好的方法,请告诉我.
谢谢!
using System.Management;
class App
{
public static void Main()
{
string clusterName = "clusterHex"; // cluster alias
string custerGroupResource = "clusterHex.internal.com"; // Cluster group name
ConnectionOptions options = new ConnectionOptions();
options.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;
// Connect with the mscluster WMI namespace on the cluster named "MyCluster"
ManagementScope s = new ManagementScope("\\\\" + clusterName +
"\\root\\mscluster", options);
ManagementPath p = new ManagementPath("Mscluster_Clustergroup.Name='" + custerGroupResource + "'");
using (ManagementObject clrg = new ManagementObject(s, p, null))
{
// Take clustergroup off line …Run Code Online (Sandbox Code Playgroud) 每次实例化一个新的时候,我想给一个类一个唯一的ID.例如,对于一个名为Foo的类,我希望能够执行以下操作
dim a as New Foo()
dim b as New Foo()
Run Code Online (Sandbox Code Playgroud)
并且a将获得唯一ID并且b将获得唯一ID.id只需要在运行时是唯一的,所以我只想使用整数.我已经找到了一种方法来做到这一点(并且这是警告)我不希望能够从任何地方更改ID.我目前关于实现此方法的想法如下:
Public Class test
Private Shared ReadOnly _nextId As Integer
Private ReadOnly _id As Integer
Public Sub New()
_nextId = _nextId + 1
_id = _nextId
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
但是这不会编译,因为它会在_nextId = _nextId + 1上抛出错误我不明白为什么这会是一个错误(因为_Id也是readonly你应该能够改变构造函数中的只读变量.我认为这也与它共享有关.任何解决方案(希望不是kludgy hehe)或解释为什么这不起作用将被接受.重要的部分是我想要两个变量(或者如果有一种方法只有一个甚至更好,但我认为不可能)在初始化对象后是不可变的.谢谢!