2013-04-12 32 views
0

我有一個在系統啓動後立即啓動的移動應用程序(用於Windows Mobile 6.1的.NET CF2)。在窗體窗體加載後調用服務

我想迫使窗體加載並調用Web服務。還有一個按鈕可以手動調用WS。

到目前爲止,我還沒有設法首先加載表單。首先它調用服務,它們顯示錶單。

你能幫我嗎?

貝婁我正在使用的代碼。

//主要應用程序

使用系統;

using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 

using System.Diagnostics; 
using System.Threading; 

namespace AtualizaColetores 
{ 
    public partial class frmInicio : Form 
    { 
     public frmInicio() 
     { 
      InitializeComponent(); 
      Program.ShowHide.ShowTopStatusbar(false); 



      ThreadPool.QueueUserWorkItem(delegate 
      { 
       Thread.Sleep(1000); 

       //incia animação para indicar processamento em segundo plano 
       Cursor.Current = Cursors.WaitCursor; 
       Cursor.Show(); 

       Atualizador executar = new Atualizador(); 
       executar.AtualizaColetor(); 
      }); 


      try 
      { 
       Process firstProc = new Process(); 
       firstProc.StartInfo.FileName = @"\WOPT\RF_WOPT.exe"; 
       firstProc.EnableRaisingEvents = true; 

       firstProc.Start(); 

       firstProc.WaitForExit(); 
       this.Activate(); 
       Form destino = new frmControles(); 
       destino.Show(); 

      } 
      catch (Exception ex) 
      { 
       MessageBox.Show("Erro na incialização do programa: " + ex.Message); 
       return; 
      } 




      //Para a animação para indicar processamento em segundo plano 
      Cursor.Current = Cursors.Default; 
      Cursor.Show(); 
     } 


    } 
} 

//中心代碼hereODE要下載並更換APP的當前版本(如果需要)

using System; 

using System.Collections.Generic; 
using System.Text; 
using System.IO; 

using System.Xml; 
using Ionic.Zip; 

namespace AtualizaColetores 
{ 
    class Atualizador 
    { 
     public void AtualizaColetor() 
     { 

      if (File.Exists(@"\WOPT\About.xml")) 
      { 
       string versaoAplicativo = "", LocalAplicativo = "", tipoColetor = ""; 

       XmlDocument xmlDoc = new XmlDocument(); 
       xmlDoc.Load(@"\WOPT\About.xml"); 

       XmlNodeList xnList = xmlDoc.GetElementsByTagName("VersaoRF"); 

       foreach (XmlNode xn in xnList) 
       { 
        versaoAplicativo = xn["versaoAplicativo"].InnerText; 
        LocalAplicativo = xn["localAplicativo"].InnerText; 
        tipoColetor = xn["tipoColetor"].InnerText; 
       } 

       ConectorWOPT.WOPT executar = new ConectorWOPT.WOPT(); 

       //inserir tratamento de erro aqui. 
       byte[] arquivo = executar.AtualizaColetores(LocalAplicativo, versaoAplicativo, tipoColetor); 

       string caminhoWOPT = @"\WOPT"; 

       if (arquivo.Length > 0) 
       { 
        try 
        { 
         MemoryStream ms = new MemoryStream(arquivo); 
         FileStream fs = new FileStream(
         @"\novaVersao.zip", FileMode.Create); 
         ms.WriteTo(fs); 
         ms.Close(); 
         fs.Close(); 
         fs = null; 
         ms = null; 
        } 
        catch (Exception ex) 
        { 
         System.Windows.Forms.MessageBox.Show(ex.Message); 
        } 

        if (System.IO.Directory.Exists(caminhoWOPT)) 
        { 
         try 
         { 
          System.IO.Directory.Delete(caminhoWOPT, true); 

          if (!System.IO.File.Exists(caminhoWOPT)) 
          { 
           System.IO.Directory.CreateDirectory(caminhoWOPT); 
          } 
         } 
         catch (IOException e) 
         { 
          System.Windows.Forms.MessageBox.Show(e.Message); 
         } 
        } 

        if (File.Exists(@"\novaVersao.zip")) 
        { 
         using (ZipFile zip = ZipFile.Read(@"\novaVersao.zip")) 
         { 
          foreach (ZipEntry e in zip) 
          { 
           e.Extract(@"\WOPT\", ExtractExistingFileAction.OverwriteSilently); // overwrite == true 
          } 
         } 
         System.IO.File.Delete(@"\novaVersao.zip"); 

         System.Windows.Forms.MessageBox.Show("Coletor atualizado com sucesso"); 

        } 
        else 
        { 
         System.Windows.Forms.MessageBox.Show("Falha na atualização"); 
        } 
       } 
      } 
      else 
      { 
       System.Windows.Forms.MessageBox.Show("O aplicativo não está instalado neste coletor. Contate um supervisor."); 
      } 

     } 
    } 
} 

回答

2

只是延遲與定時器或線程的處理。沿着這些路線的東西:

public frmInicio() 
{ 
    InitializeComponent(); 
    Program.ShowHide.ShowTopStatusbar(false); 

    ThreadPool.QueueUserWorkItem(delegate 
    { 
     Thread.Sleep(1000); // or however long you need 
     btnZip_Click(this, EventArgs.Empty); 
    }); 
} 

或將呼叫OnActivate,檢查第一次運行。

編輯1

你有很多(太多IMO)事情在你的構造函數。我敢打賭,表單可見性問題與您在表單構造函數中創建一個Process並在繼續之前等待該流程完成的事實有很大關係。如果該應用程序正在等待Web服務調用的輸出,則線程創建將毫無意義,因爲您仍然使構造函數依賴於調用。

+0

我會試試這個。我想過使用這個選項,但對我來說看起來並不「優雅」。如果它有效,沒有人會提出不同的建議,我會將你標爲awsnser!韓國社交協會。 – Andrew

+1

ctacke是對的。 AFAIK在真正展示緊湊框架表單時無法「知道」。 – josef

+0

這個解決方案不能正常工作,不幸的是...只有在WS呼叫之後才顯示窗體。我真的需要先顯示窗體,然後調用WS ... – Andrew