I'm writing a WPF / C # program with multiple interfaces. In some cases I want an interface to remain open in the background while another interface is open in foreground. To do this I've used the interface2.Show() method, without calling the interface1.Close () method on the other one. The problem is that in the task manager now I have two programs mentioned, while it is obviously only one. There is a way to have only one entry in the task manager?
It seems that my program sees every interface as a different program. Is there a way to fix it? Where am I wrong?
Thank you all!!!
UPDATE:
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>
I've posted only the code that has something to do with the two windows...
When the user click on the Button Add task, the window New Task is opened.
What I'm looking for is a way to hide the "New Task" voice in the task manager, maintaining only "scheduler", while both windows are however open.
I've found the problem. I had forgot to set the owner of the secondary windows
In the scheduler.cs i've added the following:
and in the constructor of New_task_1 i've added