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


C# Result.Block方法代码示例

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


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

示例1: DispatchLoop

        private void DispatchLoop()
        {
            // set thread-local self-reference
            CurrentThread = this;

            // begin thread loop
            try {
                while(true) {

                    // check if queue has a work-item
                    Action callback;
                    if(!_inbox.TryPop(out callback)) {
                        var result = new Result<DispatchWorkItem>(TimeSpan.MaxValue);

                        // reset the dispatch queue for this thread
                        Async.CurrentDispatchQueue = null;

                        // check if thread is associated with a host already
                        if(_host == null) {

                            // NOTE (steveb): this is a brand new thread without a host yet

                            // return the thread to the dispatch scheduler
                            DispatchThreadScheduler.ReleaseThread(this, result);
                        } else {

                            // request another work-item
                            _host.RequestWorkItem(this, result);
                        }

                        // block until a work item is available
                        result.Block();

                        // check if we received a work item or an exception to shutdown
                        if(result.HasException && (result.Exception is DispatchThreadShutdownException)) {

                            // time to shut down
                            _log.DebugFormat("DispatchThread #{0} destroyed", _id);
                            return;
                        }
                        callback = result.Value.WorkItem;
                        _queue = result.Value.DispatchQueue;

                        // TODO (steveb): handle the weird case where _queue is null

                        // set the dispatch queue for this thread
                        Async.CurrentDispatchQueue = _queue;
                    }

                    // execute work-item
                    if(callback != null) {
                        try {
                            callback();
                        } catch(Exception e) {
                            _log.Warn("an unhandled exception occurred while executing the work-item", e);
                        }
                    }
                }
            } catch(Exception e) {

                // something went wrong that shouldn't have!
                _log.ErrorExceptionMethodCall(e, string.Format("DispatchLoop #{0}: FATAL ERROR", _id));

                // TODO (steveb): tell _host about untimely exit; post items in queue to host inbox (o/w we lose them)

            } finally {
                CurrentThread = null;
            }
        }
开发者ID:maximmass,项目名称:DReAM,代码行数:69,代码来源:DispatchThread.cs

示例2: GetNextWorkItem

        // (yurig): This method has been intentionally split from DispatchLoop()
        // result.Block() inside causes Result<DispatchWorkItem> to never be disposed.
        // By moving it into its own method we ensure its garbage collection as it is
        // popped off the stack. Do NOT inline this method into DispatchLoop().
        private bool GetNextWorkItem(out Action callback)
        {
            if(!_inbox.TryPop(out callback)) {
                var result = new Result<DispatchWorkItem>(TimeSpan.MaxValue);

                // reset the dispatch queue for this thread
                AsyncUtil.CurrentDispatchQueue = null;
                _queue = null;

                // check if thread is associated with a host already
                if(_host == null) {

                    // NOTE (steveb): this is a brand new thread without a host yet

                    // return the thread to the dispatch scheduler
                    DispatchThreadScheduler.ReleaseThread(this, result);
                } else {

                    // request another work-item
                    _host.RequestWorkItem(this, result);
                }

                // block until a work item is available
                result.Block();

                // check if we received a work item or an exception to shutdown
                if(result.HasException && (result.Exception is DispatchThreadShutdownException)) {

                    // time to shut down
                    _log.DebugFormat("DispatchThread #{0} destroyed", _id);
                    return false;
                }
                callback = result.Value.WorkItem;
                _queue = result.Value.DispatchQueue;

                // TODO (steveb): handle the weird case where _queue is null

                // set the dispatch queue for this thread
                AsyncUtil.CurrentDispatchQueue = _queue;
            }
            return true;
        }
开发者ID:nataren,项目名称:DReAM,代码行数:46,代码来源:DispatchThread.cs


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