WriteAsync(byte[], int, int, CancellationToken)

The WriteAsync method returns a Task-based asynchronous version of OracleBlob.Write().

Declaration

// C#
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken);

Parameters

Return Value

Task object representing the asynchronous operation immediately without blocking the calling thread for the whole duration of the query execution.

Exceptions

Example

using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncApp
{
  class AsyncDemo
  {
    static async Task Main(string[] args)
    {
      string connectionString = "User Id=HR; Password=<PASSWORD>; Data Source=oracle;";

      OracleConnection oc = new OracleConnection(connectionString);
      await oc.OpenAsync(CancellationToken.None);

      OracleBlob blob = new OracleBlob(oc);

      byte[] writeBuffer = new byte[4] { 1, 2, 3, 4 };

      //Write data to Binary Large Object, asynchronously
      Task task = blob.WriteAsync(writeBuffer, 0, 4, CancellationToken.None);

      //other operations
      Console.WriteLine("Hello World");

      //await for asynchronous WriteAsync
      await task;
      Console.WriteLine("blob.Length  = " + blob.Length);
    }
  }
}

See Also: