이러한 방법을 사용하는 올바른 방법은 무엇입니까?
내가 아는 한 UploadFromByteArrayAsync 메서드는 바이트 배열의 내용을 파일로 업로드하기 위해 비동기 작업을 수행하는 작업을 반환합니다.
데이터를 could 파일로 비동기 적으로 전송합니다.
자세한 내용은 아래 코드를 참조 수 :
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"connectionstring");
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference("filesharename");
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
int size = 5 * 1024 * 1024;
byte[] buffer = new byte[size];
Random rand = new Random();
rand.NextBytes(buffer);
CloudFile file = rootDir.GetFileReference("Log3.txt");
file.UploadFromByteArrayAsync(buffer, 0, buffer.Length);
BeginUploadFromByteArray 방법은 파일에 바이트 배열의 내용을 업로드하는 비동기 작업을 시작합니다.
이 방법을 사용하면 프로그램이 데이터를 UploadFromByteArrayAsync와 같이 비동기 적으로 could 파일로 전송합니다.
메서드를 사용하려면 비동기 작업이 완료 될 때 알림을 받기 위해 콜백 메서드를 만들어야합니다.
자세한 내용은 아래 코드를 참조 수 :
static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"connectionstring");
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference("fileshare");
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
int size = 5 * 1024 * 1024;
byte[] buffer = new byte[size];
Random rand = new Random();
rand.NextBytes(buffer);
CloudFile file = rootDir.GetFileReference("Log3.txt");
//This string will pass to the callback function
string result = "aa";
//Begins an asynchronous operation to upload the contents of a byte array to a file. If the file already exists on the service, it will be overwritten.
var res = file.BeginUploadFromByteArray(buffer, 0, buffer.Length, ProcessInformation, result);
}
static void ProcessInformation(IAsyncResult result)
{
//The callback delegate that will receive notification when the asynchronous operation completes.
string Name = (string)result.AsyncState;
//this Name is aa
Console.WriteLine(Name);
Console.WriteLine("Complete");
}
EndUploadFromByteArray 방법이 완전히 실행 BeginUploadFromByteArray 방법 기다립니다. 그것을 사용하는 방법에 대한
, 당신은 코드 아래를 참조 수 :
static void Main(string[] args)
{
// TableTest();
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"connectionstring");
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference("fileshare");
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
int size = 5 * 1024 * 1024;
byte[] buffer = new byte[size];
Random rand = new Random();
rand.NextBytes(buffer);
CloudFile file = rootDir.GetFileReference("Log3.txt");
file.UploadFromByteArrayAsync(buffer, 0, buffer.Length);
string result = "aa";
//Begins an asynchronous operation to upload the contents of a byte array to a file. If the file already exists on the service, it will be overwritten.
var res = file.BeginUploadFromByteArray(buffer, 0, buffer.Length, ProcessInformation, result);
//Ends an asynchronous operation to upload the contents of a byte array to a file.
//wait for the BeginUploadFromByteArray method execute completely then continue run the codes
file.EndUploadFromByteArray(res);
Console.ReadLine();
}
static void ProcessInformation(IAsyncResult result)
{
//The callback delegate that will receive notification when the asynchronous operation completes.
string Name = (string)result.AsyncState;
//this Name is aa
Console.WriteLine(Name);
Console.WriteLine("Complete");
}