从namespace Download_Extract
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//static EventWaitHandle _ready = new AutoResetEvent(false);
//static EventWaitHandle _go = new AutoResetEvent(false);
// ***Download and extract***
private void Button1_Click(object sender, EventArgs e)
{
string BTurl = "https://the/file/is/located/here/self_extracting_7z_file.exe";
string BTlocation = Path.Combine(Path.GetTempPath(), "self_extracting_7z_file.exe");
startDownload(BTurl, BTlocation);
//_ready.WaitOne(); //wait here until _ready.Set() is retruned
label3.Text = "Extracting Files......."; //_ready.Set() has been received
Process.Start(BTlocation, @"-aoa -y -oc:\dest_folder").WaitForExit();
label3.Text = "Extracting Files Completed";
}
private void startDownload(string BTurl, string BTlocation)
{
Thread thread = new Thread(() => {
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri(BTurl), BTlocation);
});
thread.Start();
//_ready.Set(); // test C *ProgressBar works, but doesn't wait for completed dl before continuing
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
this.BeginInvoke((MethodInvoker)delegate {
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
label3.Visible = true;
label3.Text = "Downloading.... "; // + e.BytesReceived + " of " + e.TotalBytesToReceive;
label10.Visible = true;
label10.Text = String.Format("{0:0}", percentage) + "%";
progressBar1.Visible = true;
progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
});
//_ready.Set(); // test B *ProgressBar works, but doesn't wait for completed dl before continuing
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
this.BeginInvoke((MethodInvoker)delegate {
label10.Visible = false;
label3.Text = "Download completed.";
});
//_ready.Set(); // test A *works, but with issues. pBar delayed, no #%.text shown
}
}
}
到元组,再到对象,数字...如果用unknown
访问它们,则等于[never]
。那么,never
为何表现不同?以下是一致的,为什么?
any[never]
答案 0 :(得分:1)
我认为这是一致的。 never
是所有类型的子类型。因此可以将其分配给任何其他类型。因此,如果我们可以使用never
进行索引而不会出现编译器错误:
declare let o: never;
declare let arr: any[];
arr[o] // not error, any
其余的只是可以索引的内容。 number
和object
没有索引签名,因此结果为never
。 string
是可索引的,结果是string
,因此string[never]
是string
。 any
是通用可索引的,结果是any
,所以any[never]
是any
。
对于如上所述用never
进行索引的数组是可能的,并且将为我们提供项目类型,因此这些结果是一致的。