public async Task <TimeSpan> UpdateValue() { ReplicaKeyValue rkv; var i = 0; unsafe { var v = new IntPtr((byte *)&i); rkv = new ReplicaKeyValue(TestKey, v, 4); } var sw = Stopwatch.StartNew(); using (var tx = OpenSession()) { // ReSharper disable once ConvertClosureToMethodGroup var item = (Tuple <long, int>)tx.TryGet(TestKey, r => Parse(r)); if (item == null) { tx.Add(rkv); } else { i = item.Item2 + 1; tx.Update(rkv, item.Item1); } await tx.SaveChangesAsync(); } sw.Stop(); return(sw.Elapsed); }
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { ReplicaKeyValue rkv; var i = 0; unsafe { rkv = new ReplicaKeyValue(TestKey, new IntPtr((byte *)&i), 4); } using (var tx = OpenSession()) { tx.Add(rkv); await tx.SaveChangesAsync(); } while (true) { cancellationToken.ThrowIfCancellationRequested(); //var elapsed = await UpdateValue(); await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); } }