• 小知识


    超时取消任务:

    private async void button_Click(object sender, RoutedEventArgs e)
            {
                var feedUri = new Uri("http://news.163.com/special/00011K6L/rss_newstop.xml");
                var client = new Windows.Web.Syndication.SyndicationClient();
    
                try
                {
                    CancellationTokenSource cs = new CancellationTokenSource(10);
                    var feed = await client.RetrieveFeedAsync(feedUri).AsTask(cs.Token);
                }
                catch (Exception ex)
                {
    
                    if (ex.GetType() == typeof(System.Threading.Tasks.TaskCanceledException))
                    {
                        await new MessageDialog("Message:Task Canceled!").ShowAsync();
                    }
                    else
                    {
                        await new MessageDialog("Message:Exception!").ShowAsync();
                    }
                }
    
    
            }

    WinRT事件发生顺序:

    Page_PointerEntered
    Page_PointerPressed
    Page_PointerReleased
    Tapped  //如果长按或按着移动就没有
    Page_PointerExited
    
    
    属性设置:ManipulationMode=All”
    Page_PointerPressed
    Page_ManipulationStarting
    Page_ManipulationStarted//只有触摸滑动时才触发
    Page_ManipulationDelta
    Page_ManipulationDelta
    Page_ManipulationCompleted
    Page_PointerReleased
    
    Windows:
    属性设置:CanDrag="True" AllowDrop="True"
    Page_PointerPressed
    DragStarting
    DragEnter   //拖动窗口
    DragOver    //移动
    _Drop   //放下
    DropCompleted   //完成
    Page_PointerReleased

    HttpClient的网络请求是支持进度监控,通过异步任务的IProgress对象可以直接监控到HttpClient的网络请求返回的进度信息,返回的进度对象是HttpProgress类对象。在进度对象HttpProgress里面包含了下面的一些信息:Stage(当前的状态)、BytesSent(已发送的数据大小)、BytesReceived(已接收的数据大小)、Retries(重试的次数)、TotalBytesToSend(总共需要发送的数据大小)和TotalBytesToReceive(总共需要接收的数据大小)。网络请求进度监控的代码示例如下所示:

    // 创建IProgress<HttpProgress>对象
    
        IProgress<HttpProgress> progress = new Progress<HttpProgress>(ProgressHandler);
    
        // 在异步任务中加入进度监控
    
        HttpResponseMessage response = await httpClient.PostAsync(new Uri(resourceAddress), streamContent).AsTask(cts.Token, progress);
    
        // 进度监控的回调方法
    
        private void ProgressHandler(HttpProgress progress)
    
        {
    
            // 在这里可以通过progress参数获取到进度的相关信息
    
        }
  • 相关阅读:
    初始化mysql数据库 /usr/bin/mysql_install_db执行时报错
    CentOS7安装mysql兼容性问题
    CentOS7网络连接问题以及重启网络服务失败
    CentOS7安装nginx
    zookeeper启动时报错:Error contacting service. It is probably not running问题
    CentOS查看卸载openjdk
    使用yum命令时提示:Another app is currently holding the yum lock
    修改eclipse中文件打开默认方式
    [程序员代码面试指南]链表问题-单链表的选择排序(选择排序)
    [程序员代码面试指南]链表问题-删除无序链表中重复出现的节点
  • 原文地址:https://www.cnblogs.com/ggzone/p/4429875.html
Copyright © 2020-2023  润新知