zoukankan      html  css  js  c++  java
  • C#Monitor多线程 不阻塞线程 无法执行时 放弃

    public void TestMethod1() {
                object _lock = new object();
    
                Action a1 = () => {
                    if ( Monitor.TryEnter( _lock ) ) {
                        try {
    
                            for ( int i = 0; i < 10; i++ ) {
                                Debug.Print( "a1\t" + i );
                            }
                        } catch ( Exception ex ) {
                            Debug.Print( " a1 occur error : " + ex.Message );
                        } finally {
                            Monitor.Exit( _lock );
                        }
                    }
                };
                Action a2 = () => {
                    if ( Monitor.TryEnter( _lock ) ) {
                        try {
                            for ( int i = 0; i < 10; i++ ) {
                                Debug.Print( "a2\t" + i );
                            }
                        } catch ( Exception ex ) {
                            Debug.Print( "a2 occur error : " + ex.Message );
                        } finally {
                            Monitor.Exit( _lock );
                        }
                    }
                };
    
                Parallel.Invoke( a1, a2 );
    
    
            }
  • 相关阅读:
    使用WebViewJavascriptBridge与UIWebView交互
    使用UICollectionView
    UIButton中的**EdgeInsets是做什么用的?
    [翻译] CoreImage-with-EAGLContext
    [翻译] SAMCoreImageView
    [翻译] NSImage+HHTint
    使用iCarousel的旋转木马效果请求图片
    使用TFHpple解析html
    使用MapKit框架(持续更新)
    定制UITabBar显示样式
  • 原文地址:https://www.cnblogs.com/grj001/p/12223683.html
Copyright © 2011-2022 走看看