我是WPF的初学者,在我的应用程序中,我需要执行一系列初始化步骤,这些步骤需要7-8秒才能完成,在此期间我的UI变得无法响应.为了解决这个问题,我在一个单独的线程中执行初始化:
public void Initialization()
{
Thread initThread = new Thread(new ThreadStart(InitializationThread));
initThread.Start();
}
public void InitializationThread()
{
outputMessage("Initializing...");
//DO INITIALIZATION
outputMessage("Initialization Complete");
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了一些文章BackgroundWorker,关于它应该如何允许我保持我的应用程序响应,而不必编写一个线程来执行冗长的任务,但我没有成功地尝试实现它,任何人都可以告诉我怎么做这个使用BackgroundWorker?
谢谢,Eamonn
我通过ProcessStartInfo和process.Start()启动控制台应用程序.我想隐藏黑色的窗户.这是我的代码:
string output = "";
//Setup the Process with the ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\\WINNT\\system32\\cmd.exe";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
//Start the process
Process proc = Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud)
当我开始一个新的过程时,它会自动获得焦点.如何防止它获得焦点或者将焦点重新集中到我的应用程序?
这是我正在使用的代码:
string path = @"c:\temp\myprocess.exe";
ProcessStartInfo info = new ProcessStartInfo(path);
info.WorkingDirectory = path;
Process p = Process.Start(info);
Run Code Online (Sandbox Code Playgroud)
我只需要执行的过程不要获得焦点.
非常感谢,
Adi Barda