/// <summary> /// Add 50 items using the asynchronized API. /// </summary> static void addDataAsynchronized() { Console.WriteLine("Start testing asynchronized method."); string domainName = "AsyncDomain"; sdb.CreateDomain(new CreateDomainRequest() .WithDomainName(domainName)); Results results = new Results(); List<WaitHandle> waitHandles = new List<WaitHandle>(); try { long start = DateTime.Now.Ticks; for (int i = 0; i < MAX_ROWS; i++) { PutAttributesRequest request = new PutAttributesRequest() .WithDomainName(domainName) .WithItemName("ItemName" + i) .WithAttribute(new ReplaceableAttribute() .WithName("Value") .WithValue(i.ToString())); // Start the put attributes operation. The callback method will be called when the put attributes operation // is complete or an error occurs. IAsyncResult asyncResult = sdb.BeginPutAttributes(request, new AsyncCallback(Program.callBack), results); waitHandles.Add(asyncResult.AsyncWaitHandle); } // Wait till all the requests that were started are completed. WaitHandle.WaitAll(waitHandles.ToArray()); TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start); Console.WriteLine("Time: {0} ms Successes: {1} Errors: {2}", ts.TotalMilliseconds, results.Successes, results.Errors); } finally { sdb.DeleteDomain(new DeleteDomainRequest() .WithDomainName(domainName)); } }
/// <summary> /// Add 50 items using the synchronized API. /// </summary> static void addDataSynchronized() { Console.WriteLine("Start testing synchronized method."); string domainName = "AsyncDomain"; sdb.CreateDomain(new CreateDomainRequest() .WithDomainName(domainName)); Results results = new Results(); try { long start = DateTime.Now.Ticks; for (int i = 0; i < MAX_ROWS; i++) { try { PutAttributesRequest request = new PutAttributesRequest() .WithDomainName(domainName) .WithItemName("ItemName" + i) .WithAttribute(new ReplaceableAttribute() .WithName("Value") .WithValue(i.ToString())); sdb.PutAttributes(request); results.Successes++; } catch (Exception e) { Console.WriteLine(e.Message); results.Errors++; } } TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start); Console.WriteLine("Time: {0} ms Successes: {1} Errors: {2}", ts.TotalMilliseconds, results.Successes, results.Errors); } finally { sdb.DeleteDomain(new DeleteDomainRequest() .WithDomainName(domainName)); } }