Partager via


InitializeStorageRequest.InitializeStorageAsync Method ()

 

Asynchronously sends the request to initialize storage.

Namespace:   Microsoft.WindowsServerSolutions.Storage
Assembly:  StorageOM (in StorageOM.dll)

Syntax

public void InitializeStorageAsync()
public:
void InitializeStorageAsync()
Public Sub InitializeStorageAsync

Examples

The following code example shows how to asynchronously request to initialize storage:

try
{
   StorageManager storageManager = new StorageManager();
   storageManager.Connect();
}
catch (StorageObjectModelException stoEx)
{
   //Handle exception
}

Disk disk = storageManager.Disks.FirstOrDefault();
if (disk == null)
{
   Console.WriteLine("The disk was not found");
}
else
{
   string DISK_NAME = "IC disk";
   InitializeStorageRequest initializeStorageRequest = 
      storageManager.GetInitializeStorageRequest(false, disk.ID, DISK_NAME);
   try
   {
      initializeStorageRequest.PropertyChanged += 
          deleteVolumeRequest_PropertyChanged;
       initializeStorageRequest.Progress.PropertyChanged += 
          Progress_PropertyChanged;
      initializeStorageRequest.InitializeStorageAsync();
   }
   catch (StorageObjectModelException stoEx)
   {
      Console.WriteLine("Exception: {0}. Error Code: {1}", 
         stoEx.Message, stoEx.ErrorCode);
   }
}

The following code example shows the request delegate method:

private void initializeStorageRequest_PropertyChanged(
   object obj, PropertyChangedEventArgs args)
{
   InitializeStorageRequest initializeStorageRequest = 
      (InitializeStorageRequest)obj;
   if(initializeStorageRequest.Status == OperationStatus.Succeeded)
   {
      Console.WriteLine("Request completed successfully");
   }
   else if (initializeStorageRequest.Status == OperationStatus.Failed)
   {
      Console.WriteLine("Request failed: {0}. Error Code: {1}", 
         initializeStorageRequest.ErrorMessage, 
         initializeStorageRequest.ErrorCode);
   }
}

The following code example shows the progress delegate method:

private void Progress_PropertyChanged(
   object obj, PropertyChangedEventArgs args)
{
   InitializeStorageStepStatus initializeStorageProgress = 
      (InitializeStorageStepStatus)obj;
   Console.WriteLine("Progress Stage = {0}, Percent Complete = {1}", 
      initializeStorageProgress.Step, 
      initializeStorageProgress.PercentComplete);
}

See Also

StorageManager
Disk
InitializeStorageRequest Class
Microsoft.WindowsServerSolutions.Storage Namespace

Return to top