2016-04-09 23 views
1

Kodlama konusunda gerçekten yeniyim, hiç çalışmadım ya da benzer bir şey, sadece kendim öğreniyorum, daha önce hiç yapmadım, ancak ilk gerçek uygulamanızı yeni oluşturmaya çalışıyorum. Ancak, 2 gün boyunca anlayamadığım bazı problemlerim var, bu yüzden bana yardımcı olabileceğinizi umuyorum.Bir yöntemden bir dize alınamadı

Tamam, youtubedlCurrentWorker_Process() oluşturulmadan önce, 'public String CurrentYouTubeDLVersion' tanımladım.
Uygulamamdaki bir düğme youtubedlCompareVersion_Process() öğesini çalıştırdığında, CurrentYouTubeDLVersion dizesi, karşılaştırma noktasına geldiğinde boştur.
Aşağıda kodumun sadece bir kısmı yer almaktadır.

GetCurrentVersion daha önce kaçtı iken, CurrentVisualDVersion boşluğu CompareVersion'da neden boş?
Visual Studio'da "CurrentYouTubeDLVersion" ı tıklatsam bile, GetCurrentVersion_Process içindeki bir bağlantıyı göstermez. youtubedlGetCurrentVersion_Process yöntemle İçinde

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; 
     } 
    } 
} 
+2

çalışmalıdır ve bu hiç de kesinlikle hiçbir bağlantısı yoktur' public CurrentYouTubeDLVersion' sınıfın en üstüne eklediniz. –

+0

Grant Winney haklı. Yöntemlerinizde 'String' 'LatestYoutubeDLVersion' ve' CurrentYouTubeDLVersion' önce kaldırın. –

cevap

0

, yeni CurrentYouTubeDLVersion dize oluşturuyorsunuz ve bunun sınıfın en üstüne eklenir kamu CurrentYouTubeDLVersion tamamen ayrıdır bu.

CurrentYouTubeDLVersion = youtubedl.StandardOutput.ReadToEnd(); 

Ardından değeri youtubedlCompareVersion_Process size sunulacak: Ata yerine yeni string yaratma, yapılan sınıf düzeyindeki değişkene

string CurrentYouTubeDLVersion = youtubedl.StandardOutput.ReadToEnd(); 

.

+0

Çok teşekkürler! Bu benim sorunumu çözdü :) – Dyon

+0

Hoşgeldin @Dyon. –

0

CurrentYouTubeDLVersion önünde 'dizesini' dışarı atın ve yönteme içinde yeni `CurrentYouTubeDLVersion` dize oluşturduğunuz için bu

public youtubedlGetCurrentVersion_Process() 
    { 
     /* removed code to make easier to read */ 
     //string CurrentYouTubeDLVersion = youtubedl.StandardOutput.ReadToEnd(); 
     CurrentYouTubeDLVersion = youtubedl.StandardOutput.ReadToEnd(); 
     /* removed code to make easier to read */ 
    } 
İlgili konular