2009-09-03 3 views
1

Dans le code ci-dessous, j'essaie de référencer un fichier .dll externe, ce qui crée une barre des tâches personnalisée dans le bureau. Après quoi je crée des onglets sur la barre des tâches selon mes besoins.Problème de disposition des ressources gérées dans le formulaire de fenêtre C#

Tout fonctionne correctement, mais après avoir arrêté mon application pour créer la barre des tâches, l'espace occupé par la barre des tâches personnalisée est bloqué. ce qui signifie que les ressources ne sont pas libérées après la sortie de l'application.

J'essaye de forcer l'application à disposer des ressources non managées. Mais il aide dosent. Comment le faire ?? S'il vous plaît se référer au code ci-dessous que je suis en train avec ...

espace de noms Daemon {

public partial class MDIParent : ShellLib.ApplicationDesktopToolbar , IDisposable 
{ 

    private static MDIParent MDIParentInstance = null; 


    public MDIParent() 
    { 
     InitializeComponent(); 
     timer1.Interval = 50; 
     timer1.Enabled = true; 

    } 
    int childCount = 1; 
    int iHitcount = 0; 


    protected override void Dispose(bool disposing) 
    { 
     if (disposing) 
     { 
      if (components != null) 
      { 
       components.Dispose(); 
      } 
     } 
     base.Dispose(disposing); 
    } 


    private void MDIParent_FormClosed(object sender, FormClosedEventArgs e) 
    { 
     Taskbar.Show(); 
    } 

    public void TabIt(string strProcessName) 
    { 
     //Get the collection of opened tab names and check against the new tabs. 
     //If exists, dont allow to open the same tab again. 

     bool found = false; 

     if (Global.ExistingTabProcessNames.Count > 0) 
     { 
      foreach (string currentTab in Global.ExistingTabProcessNames) 
      { 
       if (currentTab.Equals(strProcessName)) 
       { 
        found = true; 
       } 
      } 
     } 

     if (found == false) 
     { 
      this.Show(); 

      //Creating MDI child form and initialize its fields 
      MDIChild childForm = new MDIChild(); 
      childForm.Text = strProcessName; 
      childForm.MdiParent = this; 

      //child Form will now hold a reference value to the tab control 
      childForm.TabCtrl = tabControl1; 

      //Add a Tabpage and enables it 
      TabPage tp = new TabPage(); 
      tp.Parent = tabControl1; 
      tp.Text = childForm.Text; 
      tp.Show(); 
      //child Form will now hold a reference value to a tabpage 
      childForm.TabPag = tp; 
      //Activate the MDI child form 
      childForm.Show(); 
      childCount++; 

      //Activate the newly created Tabpage 
      tabControl1.SelectedTab = tp; 
      tp.Height = tp.Parent.Height; 
      tp.Width = tp.Parent.Width; 
     } 
    } 

    private void MDIParent_Load(object sender, EventArgs e) 
    { 
     Edge = AppBarEdges.Top; 
    } 

    [System.Runtime.InteropServices.DllImport("user32.dll")] 

    private static extern int ShowWindow(IntPtr hWnd, int nCmdShow); 

    private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e) 
    { 
     iHitcount = iHitcount + 1; 
     if (iHitcount != 1) 
      BringFront(tabControl1.SelectedTab.Text.ToString()); 
    } 

    [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)] 
    private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); 

    private const int SW_SHOWNORMAL = 1; 
    private const int SW_SHOWMINIMIZED = 2; 
    private const int SW_SHOWMAXIMIZED = 3; 

    private void BringFront(string ExecutablePath) 
    { 
     Process[] Processes = Process.GetProcesses(); 

     foreach (Process clsProcess in Process.GetProcesses()) 
     { 
      if (clsProcess.ProcessName.Contains(ExecutablePath)) 
      { 

       ShowWindowAsync(clsProcess.MainWindowHandle, SW_SHOWMAXIMIZED); 
      } 
      else 
      { 
       ShowWindowAsync(clsProcess.MainWindowHandle, SW_SHOWMINIMIZED); 
      } 
     } 
    } 

    public static MDIParent MDIParentRef 
    { 
     get 
     { 
      if (MDIParentInstance == null) 
       MDIParentInstance = new MDIParent(); 

      return MDIParentInstance; 
     } 
    } 

    public void showScreen() 
    { 
     if (this.InvokeRequired == true) 
     { 
      this.Invoke(new MethodInvoker(this.showScreen)); 
     } 
     else 
     { 

      this.Show(); 
     } 
    } 

    private void timer1_Tick(object sender, EventArgs e) 
    { 
     if (Global.TabProcessNames.Count > 0) 
     { 
      foreach (string strProcessName in Global.TabProcessNames) 
      { 
       TabIt(strProcessName); 
      } 
     } 
    } 
} 

}

Répondre

1

Le appbar est éliminé par l'événement OnClosing de ApplicationDesktopToolbar. Utilisez-vous Application.Exit pour quitter votre application? De MSDN:

La méthode Application.Exit ne soulève pas les Form.Closed et Form.Closing événements [...]

+0

Ceci est une application Windows qui fonctionne en arrière-plan. Donc, si l'utilisateur veut quitter l'application, il va tuer le fichier .exe de taskmanager. – Anuya

+0

Avez-vous regardé cela? http://stackoverflow.com/questions/679214 – dtb

+0

Oui, la question est similaire à la mienne, mais aucune solution n'est fournie. Orelse, il serait mieux si je dispose globalement pour l'application. – Anuya

Questions connexes