This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16327|Reply: 5

[WinForm] How background threads operate frame web pages

[Copy link]
Posted on 1/22/2019 9:43:08 PM | | |
First of all, if I execute the following statement with a UI thread, there is no problem
        private  void button9_Click_1(object sender, EventArgs e)
        {
            mshtml. HTMLDocument doc = GetIe("URL"); GetIe is a method to get IE documents at a specified URL;
            doc.frames.item(0).document.all.item("txtLimits").innerText = "123";
        }
However, if I put it in a background thread, it throws an exception: InvalidCastException, the specified conversion is invalid, the code is as follows
   private async void button9_Click_1(object sender, EventArgs e)
        {
            Action action = new Action(test12);
            await Task.Run(action);
        }
        private void test12()
        {
            mshtml. HTMLDocument doc = GetIe("URL");
            doc.frames.item(0).document.all.item("txtLimits").innerText = "123";
        }

。。。 How to write the correct one?




Previous:Today's C# Study Notes
Next:"Senran Kagura Burst: Re:Newal" Chinese and English free version
Posted on 1/23/2019 8:03:26 AM |
Posted on 1/23/2019 9:08:36 AM |

Score

Number of participants1MB+1 contribute+1 Collapse reason
crystal0330 + 1 + 1 Very powerful!

See all ratings

 Landlord| Posted on 1/23/2019 10:04:56 PM |

Thank you very much, the problem is solved, it's just that I'm new to async and don't understand why it's written like this, it would be more perfect if you could explain it.
 Landlord| Posted on 1/24/2019 6:38:37 AM |
This post was last edited by crystal0330 on 2019-1-24 06:55

Hello, I also encountered a problem in the future:



ClickYes is a method that allows you to move the mouse to the OK button in the pop-up window and click twice



Now I have two problems:
1. Write like this,ClickYes can only letThe second click of the mouse, that is, the first click is not executed, if it is in the UI thread, it can be clicked twice;
2. I hit a breakpoint in the ClickYes method, and after the program was interrupted, I pressed F11 again, and did not execute the next code in ClickYes. So how to debug step by step?

 Landlord| Posted on 1/24/2019 2:33:03 PM |

Hello, I just tried again, and when I write like this, the winform interface is stuck again, which is the same effect as using the UI thread directly...
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com