Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions BatchDotnetQuickstart/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Auth;
using Microsoft.Azure.Batch.Common;
using Microsoft.Azure.Storage;
Expand All @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;


namespace BatchDotNetQuickstart
Expand All @@ -33,7 +34,7 @@ public class Program



static void Main()
static async Task Main()
{

if (String.IsNullOrEmpty(BatchAccountName) ||
Expand Down Expand Up @@ -61,7 +62,7 @@ static void Main()

CloudBlobContainer container = blobClient.GetContainerReference(inputContainerName);

container.CreateIfNotExistsAsync().Wait();
await container.CreateIfNotExistsAsync();

// The collection of data files that are to be processed by the tasks
List<string> inputFilePaths = new List<string>
Expand All @@ -77,7 +78,7 @@ static void Main()

foreach (string filePath in inputFilePaths)
{
inputFiles.Add(UploadFileToContainer(blobClient, inputContainerName, filePath));
inputFiles.Add(await UploadFileToContainer(blobClient, inputContainerName, filePath));
}

// Get a Batch client using account creds
Expand All @@ -93,7 +94,7 @@ static void Main()

VirtualMachineConfiguration vmConfiguration = CreateVirtualMachineConfiguration(imageReference);

CreateBatchPool(batchClient, vmConfiguration);
await CreateBatchPool(batchClient, vmConfiguration);

// Create a Batch job
Console.WriteLine("Creating job [{0}]...", JobId);
Expand All @@ -104,7 +105,7 @@ static void Main()
job.Id = JobId;
job.PoolInformation = new PoolInformation { PoolId = PoolId };

job.Commit();
await job.CommitAsync();
}
catch (BatchException be)
{
Expand Down Expand Up @@ -175,7 +176,7 @@ static void Main()
Console.WriteLine("Elapsed time: {0}", timer.Elapsed);

// Clean up Storage resources
container.DeleteIfExistsAsync().Wait();
await container.DeleteIfExistsAsync();
Console.WriteLine("Container [{0}] deleted.", inputContainerName);

// Clean up Batch resources (if the user so chooses)
Expand Down Expand Up @@ -204,7 +205,7 @@ static void Main()

}

private static void CreateBatchPool(BatchClient batchClient, VirtualMachineConfiguration vmConfiguration)
private static async Task CreateBatchPool(BatchClient batchClient, VirtualMachineConfiguration vmConfiguration)
{
try
{
Expand All @@ -214,7 +215,7 @@ private static void CreateBatchPool(BatchClient batchClient, VirtualMachineConfi
virtualMachineSize: PoolVMSize,
virtualMachineConfiguration: vmConfiguration);

pool.Commit();
await pool.CommitAsync();
}
catch (BatchException be)
{
Expand Down Expand Up @@ -274,7 +275,7 @@ private static CloudBlobClient CreateCloudBlobClient(string storageAccountName,
/// <param name="containerName">The name of the blob storage container to which the file should be uploaded.</param>
/// <param name="filePath">The full path to the file to upload to Storage.</param>
/// <returns>A ResourceFile instance representing the file within blob storage.</returns>
private static ResourceFile UploadFileToContainer(CloudBlobClient blobClient, string containerName, string filePath)
private static async Task<ResourceFile> UploadFileToContainer(CloudBlobClient blobClient, string containerName, string filePath)
{
Console.WriteLine("Uploading file {0} to container [{1}]...", filePath, containerName);

Expand All @@ -284,7 +285,7 @@ private static ResourceFile UploadFileToContainer(CloudBlobClient blobClient, st

CloudBlobContainer container = blobClient.GetContainerReference(containerName);
CloudBlockBlob blobData = container.GetBlockBlobReference(blobName);
blobData.UploadFromFileAsync(filePath).Wait();
await blobData.UploadFromFileAsync(filePath);

// Set the expiry time and permissions for the blob shared access signature.
// In this case, no start time is specified, so the shared access signature
Expand Down