ErrorObject OpenAsync(Action<ErrorObject>arg_fnRet)
2014-02-08 22:36
218 查看
ErrorObject OpenAsync(Action<ErrorObject>arg_fnRet)
上面调用其实有可能是有问题的
eo = arg_rw.OpenAsync(...) 这个eo用于检测arg_rw.OpenAsync在初期是否出现错误,一般都是没有错误的,所以可以认为总是返回True
如果OpenAsync是使用Sync(同步)模式实现了Action()而且返回了false,这时就出现了问题!
1. arg_OpenAsync开始运行
2. Action同步执行,eo = eoi; eoi是False , smph.Release();(此时由于OpenAsync使用了Sync实现,所以smph无关紧要)
3.arg_OpenAsync执行完毕,由于没有错误所有返回的是一个ErrorObject.True , 所以此时 eo 被赋值了新值 ErrorObject.True
4. 最后得到的结果错误!
正确的写法:
public static ErrorObject Open(this ReadWrite arg_rw,IPEndPoint arg_ipport) { var smph = new Semaphore(0, 1); var eo = ErrorObject.True; eo = arg_rw.OpenAsync(arg_ipport, eoi => { eo = eoi; smph.Release(); }); if(eo.IsFalse) return eo; smph.WaitOne(); return eo; }
上面调用其实有可能是有问题的
eo = arg_rw.OpenAsync(...) 这个eo用于检测arg_rw.OpenAsync在初期是否出现错误,一般都是没有错误的,所以可以认为总是返回True
如果OpenAsync是使用Sync(同步)模式实现了Action()而且返回了false,这时就出现了问题!
1. arg_OpenAsync开始运行
2. Action同步执行,eo = eoi; eoi是False , smph.Release();(此时由于OpenAsync使用了Sync实现,所以smph无关紧要)
3.arg_OpenAsync执行完毕,由于没有错误所有返回的是一个ErrorObject.True , 所以此时 eo 被赋值了新值 ErrorObject.True
4. 最后得到的结果错误!
正确的写法:
public static ErrorObject Open(this ReadWrite arg_rw,IPEndPoint arg_ipport) { var smph = new Semaphore(0, 1); var eo = ErrorObject.True; var eoI = ErrorObject.True; eo = arg_rw.OpenAsync(arg_ipport, eoi => { eoI = eoi; smph.Release(); }); if(eo.IsFalse) return eo; smph.WaitOne(); return eoI; }
相关文章推荐
- Uncaught TypeError: Object #<Object> has no method 'addEvents'
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- Actionscript Error: declaration must be contained within the <Declarations> tag, since it is not ass
- Uncaught TypeError: Object #<Object> has no method 'addEvents' ext-all-debug异常
- Uncaught TypeError: Object #<HTMLDivElement> has no method 'attr'
- 当使用JQuery的"$",抛异常Uncaught TypeError: Object #<Object> has no method 'ajax'
- TypeError: Object #<Object> has no method 'createClient'
- 出现TypeError: Object #<Object> has no method 'createClient' 错误
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- HTML5 <script>元素async,defer异步加载
- TypeError: Object #<IncomingMessage> has no method 'flash'
- Parse Fatal Error at line 41 column 24: 元素类型 "url-pattern" 必须由匹配的结束标记 "</url-pattern>" 终止
- <NEED YOUR HELP> indenty field'value after do the insert action
- 故事版(storyBoard)-lllegal configuration connection <object> cannot have a prototype objct as
- javaBean与Map<String,Object>互转
- HTTP 错误 500.19 - Internal Server Error | <compilation targetFramework="4.0">
- 6.Struts的<action input=""></action>:web.xml
- 关于<s:submit>中action属性失效的原因