所以这个类在我的主window.cs中不能做process5,我试图和主wpf同时运行这个类,这是可能的吗?主要问题: class1不像mainwindow.xaml.cs那样让我启动私有进程
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApplication3
{
private object process5;
class Class1
{
process5 = Process.Start("notepad.exe");
}
}但在主窗口中,进程1-4可以:
public partial class MainWindow : Window
{
private object process1;
private object process2;
private object process3;
private object process4;
public MainWindow()
{
/*
Task.Run(() => process1 = Process.Start("notepad.exe"));
Task.Run(() => process2 = Process.Start("calc.exe"));
Task.Run(() => process3 = Process.Start("c:\\windows\\explorer.exe"));
Task.Run(() => process4 = Process.Start("C:\\Program Files\\Adobe\\Adobe Audition CC\\Adobe Audition CC.exe"));
*/
System.Threading.Tasks.Task.Factory.StartNew(() => process1 = Process.Start("notepad.exe"));
System.Threading.Tasks.Task.Factory.StartNew(() => process2 = Process.Start("calc.exe"));
System.Threading.Tasks.Task.Factory.StartNew(() => process3 = Process.Start("c:\\windows\\explorer.exe"));
System.Threading.Tasks.Task.Factory.StartNew(() => process4 = Process.Start("C:\\Program Files\\Adobe\\Adobe Audition CC\\Adobe Audition CC.exe"));
InitializeComponent();
}
public static void MainWindow2()
{
int f = 23;
int g = 25;
MessageBox.Show("f + g = " + "" + f + g);
}
private void button1_click(object sender, RoutedEventArgs e)
{
MessageBox.Show("hi");
}
}
}发布于 2016-06-13 22:29:05
在Namespace级别没有这样的能力来拥有对象属性。
namespace WpfApplication3
{
private object process5;https://stackoverflow.com/questions/31497890
复制相似问题