【发布时间】:2016-07-30 17:41:26
【问题描述】:
我对编码真的很陌生,从未学习过它或类似的东西,只是自己学习,以前从未做过,但我正在尝试创建我的第一个真正的新应用程序。 但是,我这两天有一些问题,我就是想不通,所以希望你能帮助我。
好的,所以在创建 youtubedlCurrentWorker_Process() 之前,我确实定义了“公共字符串 CurrentYouTubeDLVersion”。
但是,当我的应用程序中的按钮执行 youtubedlCompareVersion_Process() 时,CurrentYouTubeDLVersion 字符串在比较点处为空。
下面只是我的代码的一小部分。
为什么字符串 CurrentYouTubeDLVersion 在 CompareVersion 中为空,而 GetCurrentVersion 在它之前运行?
即使我在 Visual Studio 中双击“CurrentYouTubeDLVersion”,它也不会显示指向 GetCurrentVersion_Process 中的链接。
namespace MediaDownloader
{
public partial class updates : UserControl
{
public string LatestYoutubeDLVersion;
public string CurrentYouTubeDLVersion;
public void youtubedlGetCurrentVersion_Process()
{
if (File.Exists(YouTubeDLPath))
{
//Here I get the current version of youtube-dl.exe, to get the version number, we have to run youtube-dl.exe --version
Process youtubedl = new Process();
youtubedl.StartInfo.CreateNoWindow = true;
youtubedl.StartInfo.UseShellExecute = false;
youtubedl.StartInfo.RedirectStandardOutput = true;
youtubedl.StartInfo.RedirectStandardError = true;
youtubedl.StartInfo.FileName = YouTubeDLPath;
youtubedl.StartInfo.Arguments = " --version";
youtubedl.Start();
string CurrentYouTubeDLVersion = youtubedl.StandardOutput.ReadToEnd();
this.Dispatcher.Invoke((Action)(() =>
{
CurrentYouTubeDLVersionText.Text = "Current youtube-dl.exe version: " + CurrentYouTubeDLVersion;
YouTubeDLVersionStatusText.Text = null;
UpdateYouTubeDL.IsEnabled = false;
}));
}
public void youtubedlCompareVersion_Process()
{
youtubedlGetCurrentVersion_Process();
string LatestYoutubeDLVersion = WebClient.DownloadString("https://yt-dl.org/latest/version");
MessageBox.Show("Latest:" + LatestYoutubeDLVersion + "Current " + CurrentYouTubeDLVersion);
int YouTubeDLUptodate = CurrentYouTubeDLVersion.CompareTo(LatestYoutubeDLVersion);
if (YouTubeDLUptodate < 1)
{
YouTubeDLVersionStatusText.Text = "Your youtube-dl.exe is out of date, please click the button below to update.";
UpdateYouTubeDL.IsEnabled = true;
}
else
{
YouTubeDLVersionStatusText.Text = "youtube-dl.exe is up to date!";
UpdateYouTubeDL.IsEnabled = false;
}
}
}
【问题讨论】:
-
格兰特温尼是对的。在您的方法中删除
LatestYoutubeDLVersion和CurrentYouTubeDLVersion之前的string。