当网络连接丢失3分钟或更长时间时,下面的WPF代码将永久挂起.当连接恢复时,它既不会抛出也不会继续下载或超时.如果网络连接在较短的时间内丢失(例如半分钟),则在连接恢复后会丢失.如何让网络中断更加强大?
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Windows;
namespace WebClientAsync
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
NetworkChange.NetworkAvailabilityChanged +=
(sender, e) => Dispatcher.Invoke(delegate()
{
this.Title = "Network is " + (e.IsAvailable ? " available" : "down");
});
}
const string SRC = "http://ovh.net/files/10Mio.dat";
const string TARGET = @"d:\stuff\10Mio.dat";
private async void btnDownload_Click(object sender, RoutedEventArgs e)
{
btnDownload.IsEnabled = false;
btnDownload.Content = "Downloading " + SRC;
try {
using (var wcl = new WebClient())
{ …Run Code Online (Sandbox Code Playgroud) 图像显示问题:Venus项目已滚动但其选择是可见的.
我在ListView中查看了Hanged listSelector,我正在使用形状/渐变,但是仍然没有运气.
设备:适用于Android的MS VS Emulator,Android 4.2 XHDPI API-17
IDE:适用于Windows 7 WM的Android Studio 2.
布局,主要活动
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:drawSelectorOnTop="false"
android:scrollingCache="false"
android:animationCache="false"
android:listSelector="@drawable/list_selector">
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
列表选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/item_pressed" />
<item
android:drawable="@drawable/item_selected" />
</selector>
Run Code Online (Sandbox Code Playgroud)
drawables,item_pressed
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#0000ff"
android:startColor="#0000ff" />
</shape>
Run Code Online (Sandbox Code Playgroud)
item_selected
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#00ff00" …Run Code Online (Sandbox Code Playgroud) 在判断此问题已得到回答之前,请阅读说明。我在下面有这个简单的代码:
Dictionary<string, object> d = new Dictionary<string, object>();
d.Add("key" , 30d);
System.Diagnostics.Debug.WriteLine($" TYPE OF OBJECT IS \"{d["key"].GetType()}\"");
netPlannedHours = (float)d["key"]; ---> **Line of Interest**
Run Code Online (Sandbox Code Playgroud)
当我执行这个我得到:
对象的类型为“ System.Double”。引发异常:DevOpsAutomatedReporting.dll中的“ System.InvalidCastException”无法将类型为“ System.Double”的对象转换为类型为“ System.Single”。
例外是由标记为“兴趣线”的最后一行引起的。我真的不明白为什么最后一行会导致这种情况,因为在运行时将对象的类型推断为“ System.Double”,因此它应该将其强制转换为浮点数,但事实并非如此。有趣的一点是,如果我用以下两行代码之一替换最后一行(“感兴趣的行”),它将成功将double转换为float
// Cast the double object to double again and then to float **WORKS**
netPlannedHours = (float)(double)d["key"];
// Convert to float using "Convert.ToSingle()" **WORKS**
netPlannedHours = Convert.ToSingle(d["key"]);
Run Code Online (Sandbox Code Playgroud)
请对此有所启发。谢谢!
VS20019 创建了一个面向 .net 框架(即 .net 4.7.2)的 windows 窗体项目作为“旧”样式项目。我已使用Project2015To2017.Migrate2019.Tool将新创建的项目转换为 SDK 样式。转换后的项目运行正常,但 VS20019Add/New item对话框没有显示 Winforms 部分和表单模板。仍然 VS2017Add/New item对话框成功显示 Winforms 部分。以及 VS20019 为“旧”风格的原始项目所做的。
我缺少什么?转换项目:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputPath>bin\$(Configuration)\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Deployment" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<EmbeddedResource Update="Properties\Resources.resx"> …Run Code Online (Sandbox Code Playgroud) 我得到了这个SELECT.我想计算(或总和?)玩家的黄牌和红牌(只有YellowCard = 1时才计数黄牌,而RedCard = 1时只计算红牌)..此SELECT无法正常工作.它即使有0或NULL也会计数卡.我该如何纠正它?
SELECT Firstname, Lastname, COUNT(YellowCard) AS Yellow, COUNT(RedCard) AS Red, Team.Name
FROM PlayerMatch
Inner join Player On PlayerMatch.PlayerId = Player.PlayerId
INNER JOIN Team ON Player.TeamId = Team.TeamId
INNER JOIN Match ON PlayerMatch.MatchId = Match.MatchId
WHERE(YellowCard = 1 OR RedCard = 1)
GROUP BY Lastname, Firstname, Name
ORDER BY Yellow DESC
Run Code Online (Sandbox Code Playgroud)