zoukankan      html  css  js  c++  java
  • 近期总结

    1. 线程同步:
    private
     static readonly ManualResetEvent Event = new ManualResetEvent(false);
    in the thread:
    {
      xxx
      if (Interlocked.Decrement(ref _load) == 0)
           Event.Set();
      xxx
    }

    in the main thread:
    {
     for (int i = 0; i < _load; ++i)
      {
          ThreadPool.QueueUserWorkItem(ExecuteHiveJob)
      }   Event.WaitOne();
    }

    2. C#邮件类
         private static string _userMailUser = "user@domain.com";
            private static string _userMailPassword = "xxxxxxx";
            private static string _from = "user@domain.com";
            private static string _to = "user@domain.com";
            private static string _subject = "xxxx";
            private static string _body = "xxxx";
            private static string _smtpServer = "smtp.gmail.com"; // gmail smtp server
            private static int _smtpPort = 587;
         static void Main(string[] args)
            {
                var client = new SmtpClient();
                client.Port = _smtpPort;
                client.Host = _smtpServer;
                client.EnableSsl = true;
                client.Timeout = 10000;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(_userMailUser, _userMailPassword);
     
                var mm = new MailMessage(_from, _to, _subject, _body);
                mm.BodyEncoding = UTF8Encoding.UTF8;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
     
                client.Send(mm);
            }
    
    
    3. C#异步线程调用

        
         public Task<MobileServiceCollection<T, T>> QueryRecords()
            {   
                return todoTable.ToCollectionAsync(); // 异步方法
            }

        
          // 在调用方法内,如click方法中
        
    itemsProfile = await clientProfileTable.QueryRecords(); // 使用await关键字,程序执行到这里时,会直接跳过去(返回界面),待真正查询成功后,继续执行这条语句后面的语句,很适合View Model模式的应用。
         // do something
        

    在调用过程中,也可以捕捉异常,不过需要等过一段时间才能捕捉到异常,因此,必须加await等等异常抛出并捕捉。
                try
                {
                    await BuildProfile(UserProfiles.UserName);
                }
                catch (Exception e)
                { 
                }
     







  • 相关阅读:
    html5--6-10 CSS选择器7--伪类选择器
    html5--6-9 CSS选择器6--伪类选择器
    html5--6-8 CSS选择器5
    避开美国全球监控阴影下的问题手机,寻求新伙伴
    DMA过程分析
    混淆
    Missile:双状态DP
    Java抓取网页数据(原网页+Javascript返回数据)
    Binders 与 Window Tokens(窗体令牌)
    编程之美2013 初赛一 A
  • 原文地址:https://www.cnblogs.com/codefinder/p/3673270.html
Copyright © 2011-2022 走看看