开发者

Process.Start Sometimes taking a long time to come back

I have got an odd issue in an app I am writing.

It reads a master xml config file, creates a local copy for the user then performs some actions as laid out in the xml file. It checks to see if the local xml file needs updating so it doesn't need to do it every time.

Each of the actions are run in a new thread, and once all the threads have finished it writes a log and inform the user its finished.

One of the actions is to import a .reg file into the registry. I'm doing that like so:

Process regeditProcess = Process.Start("regedit.exe", "/s " + RegFilePath);
regeditProcess.WaitForExit();
regeditProcess.Close();

The issue I have is if the application creates a new config file, then the regedit process can take anything up to 30 seconds. If it doesn't create one then it finishes within a second.

In the loop that checks the threads have finished, I have put an开发者_开发知识库

Application.DoEvents();

If I don't do this, the regedit process will run, and if I wait long enough I get a ContextSwitchDeadlock was detected error from the debugger. I have tried using different .reg file and only running this one action but still the same.

The creation of the xml file takes place in the main worker thread before any of the actions are attempted, but I'm sure this is having some effect on it, I'm just not sure what.

I know its a bit of a strange scenario, but has anyone hit something like this before?


Are you explicitly closing the file writer object after creating the config file? If not, you may be locking the file, preventing access from your worker.


I've worked out what the issue was, I had the STAThread directive in Program.cs. Once i took this out it worked a treat.

STAThread and multithreading

http://ilvyanyatka.spaces.live.com/blog/cns!EA0C02AB2E2FCFAC!193.entry?wa=wsignin1.0&sa=143328961

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜