1

I have a Powershell script with a Windows Forms UI from which I create a new Powershell instance, which in turn starts IE (hidden) and grabs information from a website.

Sometimes the UI locks up and only becomes responsive again after manually killing the hidden IE-process via task manager. Seemingly IE freezes and this locks up the UI.

Mainly I am trying to understand why this happens. Although it happens every day, so far I was not able to reproduce it by i.e. intentionally creating a new thread which does not respond. Also I thought a new instance can never lock the main thread anyway, or am I wrong and it is to be expected?

$script:Posh1 = [PowerShell]::Create()
$script:Posh1.AddScript($IEcode)
$script:Posh1.AddParameter("url1",$url1)
$script:Posh1.AddParameter("url2",$url2)
$script:Posh1.BeginInvoke()
Moss
  • 325
  • 2
  • 16
  • Try to perform the whole process manually in IE and check whether there is something which can make the IE object unresponsive. For example, check whether there is any alert or popup box from web page which needs to close to free the object. Try to provide more information about the issue. If that site is public than you can try to provide your sample script to test the issue on our end. It can help us to understand the issue in better way. – Deepak-MSFT Sep 05 '19 at 13:16
  • Thanks but I know what can make IE freeze: practically everything nowadays. :) My problem is not that IE becomes unresponsive, in fact I have a whatchdog function in place that kills IE if that happens. My problem is that the IE-thread locks up the main thread, so my watchdog function does not work anymore. I want to know if there is anything I can do about or if the solution has to be creating a seperate process (which I like to avoid) – Moss Sep 05 '19 at 13:24
  • In that case you have to use multiple threads. So that you can check whether IE is responsive or not by checking it's ready state using some other thread. – Deepak-MSFT Sep 05 '19 at 13:29
  • I thought I was doing that already. :-) Or do you mean multiple processes? If [PowerShell]::Create() does not create a new Thread, what does? Thanks! – Moss Sep 05 '19 at 14:39
  • You need to get the object of that running IE to check it's ready state. Now it depends what logic you use to perform this. – Deepak-MSFT Sep 05 '19 at 14:43
  • Sorry but that is not my problem. I cant check whether IE is locked, when it lockes up my main thread from which I would check that. What is the point of creating another whatever this is (the docu calls it instance, instance of what?) if it can simply lock up my whole app? – Moss Sep 05 '19 at 16:05
  • This is the default behavior of IE that when you try to automate it and if it get any prompt or alert which needs user interaction or any other thing that can cause IE hang than your automation code also will get stopped at that position and you will not able to do anything further also in your main thread. So If you are not able to check it using other process or thread than I am not sure about any other way. – Deepak-MSFT Sep 06 '19 at 09:20
  • Forget IE.:) This is NOT about IE.._____ Is it normal, that a process started in a second thread (see code) is able to lock up the MAIN thread as well? And if so, is there any way to avoid that, besides running the code in a seperated, second powershell? – Moss Sep 06 '19 at 15:35
  • 1
    Yes, it is normal. In many scenarios IE do that. in your case, we need to find why IE is doing that. your above code example will not give any information about that. You need to post your detailed sample code to check the issue. – Deepak-MSFT Sep 10 '19 at 01:18
  • I know why its doing that. Its a crappy browser. :) Nevermind. – Moss Sep 25 '19 at 17:09

0 Answers0