当前位置: 首页>>代码示例>>C#>>正文


C# Result.WhenDone方法代码示例

本文整理汇总了C#中System.Result.WhenDone方法的典型用法代码示例。如果您正苦于以下问题:C# Result.WhenDone方法的具体用法?C# Result.WhenDone怎么用?C# Result.WhenDone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Result的用法示例。


在下文中一共展示了Result.WhenDone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDocumentResponse

 private static object GetDocumentResponse(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     var docResponse = new Result<XDoc>();
     docResponse.WhenDone(
         r => response.Return(DreamMessage.Ok(r)),
         response.Throw);
     return docResponse;
 }
开发者ID:aaronmars,项目名称:DReAM,代码行数:8,代码来源:DreamFeatureStage.cs

示例2: Write

        private Result Write(Action<string> activity, Stream stream, byte[] buffer, int offset, int count, Result result)
        {
            // asynchronously execute read operation
            Result<IAsyncResult> inner = new Result<IAsyncResult>(TimeSpan.MaxValue);
            inner.WhenDone(delegate(Result<IAsyncResult> _unused) {
                try {
                    activity(string.Format("pre {0}!EndWrite", stream.GetType().FullName));
                    stream.EndWrite(inner.Value);
                    activity("post EndWrite");
                    result.Return();
                } catch(Exception e) {
                    activity("throw Write 1");
                    result.Throw(e);
                }
            });
            try {
                activity(string.Format("pre {0}!BeginWrite", stream.GetType().FullName));
                stream.BeginWrite(buffer, offset, count, inner.Return, stream);
                activity("post BeginWrite");
            } catch(Exception e) {
                activity("throw Write 2");
                result.Throw(e);
            }

            // return yield handle
            return result;
        }
开发者ID:heran,项目名称:DReAM,代码行数:27,代码来源:httptransport.cs

示例3: Result_with_current_state_should_get_original_state_on_whendone_with_return_before_whendone

 public void Result_with_current_state_should_get_original_state_on_whendone_with_return_before_whendone()
 {
     var state = new TaskLifeSpanState("baz");
     TaskEnv.Current.SetState(state);
     var allgood = false;
     var resetEvent = new ManualResetEvent(false);
     var r = new Result(TaskEnv.Current);
     r.Return();
     r.WhenDone(r2 => {
         allgood = !r2.HasException && state == TaskEnv.Current.GetState<TaskLifeSpanState>();
         resetEvent.Set();
     });
     resetEvent.WaitOne();
     Assert.IsTrue(allgood);
 }
开发者ID:bjorg,项目名称:DReAM,代码行数:15,代码来源:TaskTests.cs

示例4: WhenDone_triggers_state_disposal

 public void WhenDone_triggers_state_disposal()
 {
     var state = new TaskLifeSpanState("baz");
     Assert.IsFalse(state.IsDisposed);
     TaskEnv.Current.SetState(state);
     var resetEvent = new ManualResetEvent(false);
     var result = new Result(TaskEnv.Current);
     _log.Debug("setting up whendone");
     result.WhenDone(r => {
         _log.Debug("whendone called");
         resetEvent.Set();
     });
     result.Return();
     resetEvent.WaitOne();
     Assert.IsTrue(Wait.For(() => state.IsDisposed, TimeSpan.FromSeconds(10)));
 }
开发者ID:bjorg,项目名称:DReAM,代码行数:16,代码来源:TaskTests.cs

示例5: HandleInvoke

        private Yield HandleInvoke(Action<string> activity, Plug plug, string verb, XUri uri, DreamMessage request, Result<DreamMessage> response)
        {
            Result<IAsyncResult> async;

            // remove internal headers
            request.Headers.DreamTransport = null;

            // set request headers
            request.Headers.Host = uri.Host;
            if(request.Headers.UserAgent == null) {
                request.Headers.UserAgent = "Dream/" + DreamUtil.DreamVersion;
            }

            // add cookies to request
            if(request.HasCookies) {
                request.Headers[DreamHeaders.COOKIE] = DreamCookie.RenderCookieHeader(request.Cookies);
            }

            // check if we can pool the request with an existing one
            if((plug.Credentials == null) && StringUtil.ContainsInvariantIgnoreCase(verb, "GET")) {

                // create the request hashcode
                StringBuilder buffer = new StringBuilder();
                buffer.AppendLine(uri.ToString());
                foreach(KeyValuePair<string, string> header in request.Headers) {
                    buffer.Append(header.Key).Append(": ").Append(header.Value).AppendLine();
                }
                Guid hash = new Guid(StringUtil.ComputeHash(buffer.ToString()));

                // check if an active connection exists
                Result<DreamMessage> relay = null;
                lock(_requests) {
                    List<Result<DreamMessage>> pending;
                    if(_requests.TryGetValue(hash, out pending)) {
                        relay = new Result<DreamMessage>(response.Timeout);
                        pending.Add(relay);
                    } else {
                        pending = new List<Result<DreamMessage>>();
                        pending.Add(response);
                        _requests[hash] = pending;
                    }
                }

                // check if we're pooling a request
                if(relay != null) {

                    // wait for the relayed response
                    yield return relay;
                    response.Return(relay);
                    yield break;
                } else {

                    // NOTE (steveb): we use TaskEnv.Instantaneous so that we don't exit the current stack frame before we've executed the continuation;
                    //                otherwise, we'll trigger an exception because our result object may not be set.

                    // create new handler to multicast the response to the relays
                    response = new Result<DreamMessage>(response.Timeout, TaskEnv.Instantaneous);
                    response.WhenDone(_ => {
                        List<Result<DreamMessage>> pending;
                        lock(_requests) {
                            _requests.TryGetValue(hash, out pending);
                            _requests.Remove(hash);
                        }

                        // this check should never fail!
                        if(response.HasException) {

                            // send the exception to all relays
                            foreach(Result<DreamMessage> result in pending) {
                                result.Throw(response.Exception);
                            }
                        } else {
                            DreamMessage original = response.Value;

                            // only memorize the message if it needs to be cloned
                            if(pending.Count > 1) {

                                // clone the message to all relays
                                foreach(Result<DreamMessage> result in pending) {
                                    result.Return(original.Clone());
                                }
                            } else {

                                // relay the original message
                                pending[0].Return(original);
                            }
                        }
                    });
                }
            }

            // initialize request
            activity("pre WebRequest.Create");
            var httpRequest = (HttpWebRequest)WebRequest.Create(uri.ToUri());
            activity("post WebRequest.Create");
            httpRequest.Method = verb;
            httpRequest.Timeout = System.Threading.Timeout.Infinite;
            httpRequest.ReadWriteTimeout = System.Threading.Timeout.Infinite;

            // Note (arnec): httpRequest AutoRedirect is disabled because Plug is responsible for it (this allows redirects to follow
//.........这里部分代码省略.........
开发者ID:melder,项目名称:DReAM,代码行数:101,代码来源:HttpPlugEndpoint.cs


注:本文中的System.Result.WhenDone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。