So I have been battling this issue for awhile now and tried many different ways to fix it but cannot.
Bascally waht my app does is calls a java file to load an applica
Trying moving the WaitForExit
call out of the UI thread.
As @M. Babcock mentioned, you are holding up updates to the rich text box.
A solution similar to this may work:
Modify btnLoad_Click
to start a new thread that processes the list (this goes in the count > 0 branch)
Thread thread = new Thread(new ThreadStart(LoadPbThread));
thread.Start();
Then, add this:
void LoadPbThread()
{
String toLoad;
for (int i=0; i < count;i++)
{//START OF FOREACH
toLoad = lstBarToLoad.Items[i].Text;
//call load method.
loaddPB(toLoad);
}//end of for.
}
If you WaitForExit, your application blocks (waits) until the process exits. This means it is unable to process any Windows messages in its UI thread, so it doesn't update the UI.
You need to start the process "in the background" so your UI continues to refresh. This can be done with:
Sit in a busy wait loop until it completes, and process application events. (Beware of this, as any events that cause reentrant calls to this code could do very bad things. Generally if you use this approach you nee dto make sure that the rest of your application is "locked down" in a state where it knows it is busy waiting for a process to complete). THis is effectively what WaitForExit does, but it also processes application events, allowing the UI to remain vaguely responsive:
while (!process.HasExited)
{
Application.DoEvents();
Thread.Sleep(100);
}
I may be totally wrong here, but...
process1.StartInfo.Arguments = "-Xmx512M -jar";
process1.StartInfo.Arguments += toLoad;
You need to have a space after the -jar
Or else Java is going to immediately bomb out.
As it is adviced here, setting process.EnableRaisingEvents = true solved the problem of the blocked ui in my case.