I am confused between Managed and unmanaged resources in .net programming. I am developing a vb.net application. I read in Microsoft website that, if we use Managed resources garbage collector will dispose it and if we use unmanaged resources we need to call dispose. But I didn't get the answer to following questions anywhere.
IDisposable
its unmanaged or contains some unmanagedIDisposable
anywhere you use some managed code, but with .net having a good GC unless you somehow lock the unmanaged res. you should be ok. var credentials = SdkContext.AzureCredentialsFactory
.FromServicePrincipal(clientId, clientSecret, tenantId,
AzureEnvironment.AzureGlobalCloud);
var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithSubscription(subscriptionID);
List<IStorageAccount> storageAccounts =
azure.StorageAccounts.List().ToList();
foreach (IStorageAccount storageaccount in storageAccounts)
{
var exportSecrets = true;
CloudStorageAccount storageAccountss = new CloudStorageAccount(
new StorageCredentials(storageaccount.Name,
storageaccount.GetKeys().FirstOrDefault().Value), true);
var connString = storageAccountss.ToString(exportSecrets);
var storageAccount = CloudStorageAccount.Parse(connString);
CloudBlobClient myClient = storageAccount.CreateCloudBlobClient();
ContainerResultSegment resultSegment = null;
BlobContinuationToken continuationToken = null;
resultSegment = myClient.ListContainersSegmented("",
ContainerListingDetails.Metadata, 5, continuationToken, null,
null);
// Enumerate the containers returned.
foreach (var container in resultSegment.Results)
{
var containers = myClient.GetContainerReference(container.Name);
foreach (IListBlobItem item in container.ListBlobs(null, false,
BlobListingDetails.None))
{
if (item.GetType() == typeof(CloudPageBlob))
{
CloudPageBlob pageBlob = (CloudPageBlob)item;
if (pageBlob.Name.Contains(".vhd"))
{
// 0. Unspecified 1. Locked 2. UnLocked
if (Convert.ToInt32(pageBlob.Properties.LeaseStatus)
== 2)
{
list.Add(new Disks { Name =
pageBlob.Name.ToString(), URI =
pageBlob.Uri.AbsoluteUri.ToString(),
ContainerName = container.Name.ToString() });
}
}
}
}
}
}
Helper helper = new Helper();
StringBuilder sb = new StringBuilder();
DataTable dt = helper.GetData(list);
foreach (DataRow dr in dt.Rows)
{
foreach (DataColumn dc in dt.Columns)
sb.Append(FormatCSV(dr[dc.ColumnName].ToString()) + ",");
sb.Remove(sb.Length - 1, 1);
sb.AppendLine();
}
File.WriteAllText("D:\\UnmanagedDisks.csv", sb.ToString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.