You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WPF_Practice/PacticeSolution/WpfApp1/MainWindow.xaml.cs

90 lines
2.2 KiB

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Timers;
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.Navigation;
using System.Windows.Shapes;
namespace WpfApp1
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
private string _path;
private int _interval;
private System.Timers.Timer _timer;
public MainWindow()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
_timer = new System.Timers.Timer();
_timer.Elapsed += _timer_Elapsed;
}
private void btnPath_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() != true)
return;
tbPath.Text = dlg.FileName;
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(tbPath.Text))
return;
if (string.IsNullOrEmpty(tbInterval.Text))
return;
try
{
_path = tbPath.Text;
_timer.Interval = int.Parse(tbInterval.Text);
_timer_Elapsed(this, null);
_timer.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
string processName = System.IO.Path.GetFileNameWithoutExtension(_path);
foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName.StartsWith(processName))
process.Kill();
}
Thread.Sleep(10 * 1000);
Process.Start(_path);
}
}
}