从流程任务管理器隐藏接口

时间:2017-07-17 14:02:08

标签: c# wpf multiple-interface-implem

我正在编写具有多个接口的WPF / C#程序。在某些情况下,我希望界面在后台保持打开,而另一个界面在前台打开。为此,我使用了interface2.Show()方法,而没有在另一个上调用interface1.Close()方法。问题是,在任务管理器中,我现在提到了两个程序,而显然只有一个。有一种方法只在任务管理器中有一个条目? My task manager with multiple voices

似乎我的程序将每个界面视为一个不同的程序。有办法解决吗?我哪里错了?

谢谢大家!!!

更新:

scheduler.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.Threading;
using System.ComponentModel;
using System.IO;
using System.Net.Mail;
using System.Net.Security;
using System.Data.SqlClient;
using System.Reflection;


namespace Testing_Application
{
    /// <summary>
    /// Interaction logic for scheduler.xaml
    /// </summary>
    public partial class scheduler : Window
    {

        ParallelTaskScheduler sch;

        Dictionary<string, string> dict_type;
        Dictionary<string, string> dict_value;
        Dictionary<string, string> dict_default;

        private string className;
        public string status_active = "Status: active";
        public string status_idle = "Status: idle";

        public scheduler()
        {
            InitializeComponent();
            className = this.GetType().ToString().Substring(this.GetType().ToString().LastIndexOf('.') + 1);
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            sch = new ParallelTaskScheduler(4);
            updateLanguageDatabase();
            updateLanguage();
            loadContext();
            updateList();
        }


        private void add_task_Click(object sender, RoutedEventArgs e)
        {
            New_task_1 win1 = new New_task_1();
            win1.ShowDialog();
        }


        public void add_new_task(int id)
        {
            Job j1 = new Job(id);
            j1.updateJob();
            sch.QueueJob(j1, false);
            if (sch.stop_scheduler == false) {
                sch.StopTasks();
                sch.RunTasks();
            }
        }

        private void send_log_Click(object sender, RoutedEventArgs e) {

        <ect... this methods are interaction logic of the scheduler....>

    }

}

scheduler.xaml:

<Window x:Class="Testing_Application.scheduler"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Activated="window_Activated"
    Closing="schedulerWindow_Closing"
    Title="Scheduler" Height="608.582" Width="705" ResizeMode="CanMinimize">
<Grid>
    <Button Name="start_button" Content="Start" HorizontalAlignment="Left" Margin="345,514,0,0" VerticalAlignment="Top" Width="100" Click="start_button_Click" Height="41"/>
    <Button Name="stop_button" Content="Stop" HorizontalAlignment="Left" Margin="468,514,0,0" VerticalAlignment="Top" Width="100" Click="stop_button_Click" IsEnabled="False" Height="41"/>
    <Button Name="add_task" Content="Add task" HorizontalAlignment="Left" Margin="363,34,0,0" VerticalAlignment="Top" Width="100" Click="add_task_Click" Height="32"/>
    <ListView Name="programmed_task_List" HorizontalAlignment="Left" Height="169" Margin="24,118,0,0" VerticalAlignment="Top" Width="649" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" MouseDoubleClick="programmed_task_List_MouseDoubleClick">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="ID" Width="40" DisplayMemberBinding="{Binding ID}" />
                <GridViewColumn Header="Status" Width="40" DisplayMemberBinding="{Binding Status}" />
                <GridViewColumn Header="Recursive" Width="40" DisplayMemberBinding="{Binding Recur}" />
                <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
                <GridViewColumn Header="Date" Width="120" DisplayMemberBinding="{Binding Date}" />
                <GridViewColumn Header="Process" Width="219" DisplayMemberBinding="{Binding Process}" />
            </GridView>
        </ListView.View>
    </ListView>
    <Button x:Name="config_Button" Content="Configure parameters" HorizontalAlignment="Left" Margin="24,514,0,0" VerticalAlignment="Top" Width="140" Height="41" Click="config_Button_Click"/>
    <Button x:Name="remove_task" Content="Remove task" HorizontalAlignment="Left" Margin="573,34,0,0" VerticalAlignment="Top" Width="100" Click="remove_task_Click" Height="32"/>
    <Label Name="status_label" Content="Status: idle" HorizontalAlignment="Left" Foreground="DarkGray" Margin="24,23,0,0" VerticalAlignment="Top" Height="43" Width="254" FontSize="20"/>
    <ListView x:Name="executed_task_List" HorizontalAlignment="Left" Height="150" Margin="24,344,0,0" VerticalAlignment="Top" Width="649" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" MouseDoubleClick="executed_task_List_MouseDoubleClick">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="ID" Width="40" DisplayMemberBinding="{Binding ID}" />
                <GridViewColumn Header="Status" Width="40" DisplayMemberBinding="{Binding Status}" />
                <GridViewColumn Header="Recursive" Width="40" DisplayMemberBinding="{Binding Recur}" />
                <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
                <GridViewColumn Header="Date" Width="120" DisplayMemberBinding="{Binding Date}" />
                <GridViewColumn Header="Process" Width="219" DisplayMemberBinding="{Binding Process}" />
            </GridView>
        </ListView.View>
    </ListView>
    <Label Name="done_jobs_Label" Content="Done jobs:" HorizontalAlignment="Left" Margin="24,313,0,0" VerticalAlignment="Top" Width="413"/>
    <Label Name ="programmed_jobs_Label" Content="Programmed jobs:" HorizontalAlignment="Left" Margin="24,87,0,0" VerticalAlignment="Top" Width="413"/>
    <Menu HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" Width="699">
        <MenuItem Name="mni_Utils" Header="_Utils">
            <MenuItem Name="mni_ViewLog" Header="_View Log" Click="view_log_Click" />
            <MenuItem Name="mni_SendLog" Header="_Send Log" Click="send_log_Click" />
            <MenuItem Name="mni_EraseLog" Header="_Erase Log" Click="erase_log_Click" />
            <Separator />
            <MenuItem Name="mni_Exit" Header="_Exit" Click="exit_menu_Click" />
        </MenuItem>
        <MenuItem Name="mni_Language" Header="_Language">
            <MenuItem Name="mni_LanguageSel" Header="_Select a language" Click="language_sel_Click" />
            <MenuItem Name="mni_LanguageTrad" Header="_Translate" Click="translate_Click" />
        </MenuItem>
    </Menu>
    <Button x:Name="edit_task" Content="Edit task" HorizontalAlignment="Left" Margin="468,34,0,0" VerticalAlignment="Top" Width="100" Click="edit_task_Click" Height="32"/>
    <Button x:Name="exit_button" Content="Exit" HorizontalAlignment="Left" Margin="593,522,0,0" VerticalAlignment="Top" Width="80" Click="exit_button_Click" Height="25"/>

</Grid>
</Window>

New_task_1.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.IO;
using System.Data.SqlClient;
using System.Reflection;

namespace Testing_Application
{
    /// <summary>
    /// Interaction logic for New_task_1.xaml
    /// </summary>
    public partial class New_task_1 : Window
    {

        Boolean edit = false;
        int ID = -1;
        private string className;
        Dictionary<string, string> dict_type;
        Dictionary<string, string> dict_value;
        Dictionary<string, string> dict_default;



        public New_task_1(int id)
        {
            InitializeComponent();
            this.
        className = this.GetType().ToString().Substring(this.GetType().ToString().LastIndexOf('.') + 1);
            updateLanguageDatabase();
            updateLanguage();
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            ID = id;
            loadTask(ID);
            edit = true;
        }

        public New_task_1()
        {
            InitializeComponent();
            className = this.GetType().ToString().Substring(this.GetType().ToString().LastIndexOf('.') + 1);
            updateLanguageDatabase();
            updateLanguage();
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
        }

        public void next_Button_Click(object sender, RoutedEventArgs e)
        {
             <ect... other methods>

        }
    }
}

New_task_1.xaml:

<Window x:Class="Testing_Application.New_task_1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Activated="window_Activated"
    Title="New task" Height="300" Width="542" ResizeMode="CanMinimize">
<Grid>
    <Label Name="step1_label" Content="New task" HorizontalAlignment="Left" Margin="10,77,0,0" VerticalAlignment="Top" Width="113" Background="Aquamarine"/>
    <Label Name="step2_label" Content="Trigger" HorizontalAlignment="Left" Margin="10,103,0,0" VerticalAlignment="Top" Width="113"/>
    <Label Name="step3_label" Content="Action" HorizontalAlignment="Left" Margin="10,129,0,0" VerticalAlignment="Top" Width="113"/>
    <Label Name="courtesy" Content="Create a new task" HorizontalAlignment="Left" Height="50" Margin="10,22,0,0" VerticalAlignment="Top" Width="514" FontSize="20"/>
    <Label Name="information" Content="Use this wizard to quickly schedule a new task." HorizontalAlignment="Left" Height="26" Margin="154,77,0,0" VerticalAlignment="Top" Width="370"/>
    <Label Name="name_label" Content="Name:" HorizontalAlignment="Left" Margin="154,103,0,0" VerticalAlignment="Top" Width="75"/>
    <Label Name="desc_label" Content="Description:" HorizontalAlignment="Left" Margin="154,129,0,0" VerticalAlignment="Top" Width="75"/>
    <TextBox Name="name_textBox" HorizontalAlignment="Left" Height="26" Margin="234,103,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="290"/>
    <TextBox Name="descr_textBox" HorizontalAlignment="Left" Height="80" Margin="234,129,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="290"/>
    <Button Name="next_Button" Content="Next" HorizontalAlignment="Left" Height="21" Margin="355,229,0,0" VerticalAlignment="Top" Width="82" Click="next_Button_Click"/>
    <Button Name="cancel_Button" Content="Cancel" HorizontalAlignment="Left" Height="21" Margin="442,229,0,0" VerticalAlignment="Top" Width="82" Click="cancel_Button_Click"/>

    <Menu HorizontalAlignment="Left" Height="23" VerticalAlignment="Top" Width="545">
        <MenuItem Name="mni_Language" Header="_Language">
            <MenuItem Name="mni_LanguageSel" Header="_Select a language" Click="language_sel_Click" />
            <MenuItem Name="mni_LanguageTrad" Header="_Translate" Click="translate_Click" />
        </MenuItem>
    </Menu >

</Grid>
</Window>

我只发布了与两个窗口有关的代码......

当用户点击Button Add任务时,将打开New Task窗口。

我正在寻找的是一种隐藏&#34;新任务的方法&#34;任务管理器中的语音,只维护&#34;调度程序&#34;,而两个窗口都是打开的。

1 个答案:

答案 0 :(得分:0)

我发现了问题。我忘了设置辅助窗口的所有者

在scheduler.cs中,我添加了以下内容:

public partial class scheduler : Window
{

    <other code>

    public static Window main;

    public scheduler()
    {

        <other code>

        main = this;

    }

    <other code>
}

并在New_task_1的构造函数中添加了

this.Owner = scheduler.main;