WebBrowser control never fires DocumentCompleted event - c#

I have a following code inside windows forms application but web_DocumentCompleted event never fires on my windows 10 machine
What's bothering me is that the same code works just fine if I compile it and run it on my VPS (windows server 2012R2), or machine which has windows 8.1 installed.
All machines have Internet Explorer 11 installed.
public Form1()
{
InitializeComponent();
//Web Browser control
this.web.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(web_DocumentCompleted);
this.web.Navigate(URL);
}
void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//or any other code
MessageBox.Show("Done");
}
I have tried to remove update KB3132372 as suggested on this link, but it did not help.
Why does this code works fine on windows 8.1 or Windows Server 2012, but it does not work on two separate windows 10 machines?

I have the same issue. DocumentCompleted Event is never called when ReadyState == WebBrowserReadyState.Complete.
The issue I have is that the "Document.Body.KeyDown" event cannot be called unless the Body is created. It is created of course when the document is completed.
The hack I found is to create a while loop and execute a "Application.DoEvents()" until the "ReadyState == WebBrowserReadyState.Complete". Right after that you can be certain that the Document has been completed.

Related

Setting Label.Text too frequently causes an app crash - Xamarin.Forms

I am working on an MQTTnet application for mobile/wearable devices. I've tested my code in both a standard C# Console application and .Net Core application, both work as expected. The issue I am having is when I port the code to Xamarin Forms, for running on a Galaxy Watch. The app will run for a few seconds, but then it will crash. I believe it could be from assigning the Label text too often?
I have an MQTT publisher device pumping out a simple position value at a 10ms interval. Where my other apps will just keep chugging along, the app in Xamarin will lock and then eventually crash. If it comment out the Label.Text assignment, the app keeps running without a crash.
Here is my Xamarin code, is there a better way to handle the assignment?
// Event Handler to the ApplicationMessageRecevied event
client.ApplicationMessageReceived += (s, e) =>
{
StatusLabel.Text = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
};
I found that using the following to assign the label works well. My publisher is sending messages at 2ms intervals, and the watch is stable!
Device.BeginInvokeOnMainThread(() => {
PositionData.Text = Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
});

OnSuspending event not triggered with UWP Windows 10

The OnSuspending event is not triggered for my UWP app but this problem only occurs on Windows Phone running Windows 10. It works as expected when running it as a Windows Store app on my local machine or the simulator.
I'm using this event to save my app's settings when the app is closing, but this is obviously causing a major problem for windows phone since this event is not triggered.
As you can see, the OnSuspending event is initialized when the app starts
public App()
{
Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
Microsoft.ApplicationInsights.WindowsCollectors.Session);
this.InitializeComponent();
this.Suspending += OnSuspending;
}
Below is the OnSuspending code that should be called but isn't when running in Windows Phone 10.
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
await Locator.MainPageViewModel.SaveSettings();
deferral.Complete();
}
Any ideas on how I can resolve this or is there a potential work-around?
Thanks.
UPDATE-1:
When I terminate my app by holding the flag key and click on the cross to terminate it, is closes the app but it still doesn't trigger the OnSuspending event, but the .net IDE still runs. When I press F5 to run the app again, it then triggers the OnSuspending event. My app starts but the code stops running in the IDE.
From the official App lifecycle documentation:
A note about debugging using Visual Studio: Visual Studio prevents Windows from suspending an app that is attached to the debugger. This is to allow the user to view the Visual Studio debug UI while the app is running. When you're debugging an app, you can send it a suspend event using Visual Studio. Make sure the Debug Location toolbar is being shown, then click the Suspend icon.
That means that the OnSuspending event won't get fired while you are attached to the Visual Studio debugger. If you want to debug it, manually send the event by selecting the respective Lifecycle Event.

using SpeechRecognizerUI in my WP 8 app causing it crash unexpectedly?

I am new to windows phone app development. I am trying to build a simple speech recognition app using SpeechRecognizerUI class. But the problem is whenever i try to debug the app in my Lumia 520 device(working on 8.1 platform), it load the listener as usual and then debugger stopped automatically at the same time it load within a second, don't allow me sufficient time to speak even a single word. I am googling since 2 days but got nothing helpful. I have provided a single button on "MainPage.xml" of my app for which i have given the following code.
namespace Kundali
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private async void button_Click(object sender, RoutedEventArgs e)
{
![SpeechRecognizerUI][1] sprec = new SpeechRecognizerUI();
SpeechRecognitionUIResult result = await sprec.RecognizeWithUIAsync();
MessageBox.Show(string.Format("You said {0} ", result.RecognitionResult.Text));
}
}
When i tried to handle the exception in catch handler it shows the exception "The text associated with this error code could not be found" not even listening the single text. Some one please help me.
Actually i am working with Visual studio 2012 (Express for windows Phone 8) but my device is on 8.1. Is this the problem?? If yes then please provide the solution. How do i integrate the functionality of 8.1 in vs2012?
I can think of two possible causes:
Did you add the Speech capability and the Microphone capability in your manifest WMAppManifest.xml file?
Do you have speech support for your current language? (Try setting to en-US to test)
Did you try using TTS (Text to Speech) which is also compatible with Windows Phone 8.1?
Sample
Windows Phone 8.1 Text to Speech

Silverlight - Run Method at Application start on server side

I have a Silverlight-Application which is hosted in a ASP.NET-Site. Now, I need to execute something at the first start of the application (run code for update database). I am searching the right place to do this.
Can anybody help me where I have to put this code? - Thanks.
You can add to the Startup event in your Application class, e.g.
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
... startup code here
}
}
See MSDN. Note that this runs on the client side - not the server side. Code in your silverlight application does not run on the server.
If your code has to run on the server, host your silverlight control in an aspx page and override the page's Page_Load event to execute code BEFORFE the silverlight client is sent to the browser.

Prevent windows Shutdown with CANCEL option C#

I'm trying to include in my Windows Form App a way that when user tries to shutdown windows it opens a dialog box with CANCEL option....that office classic one.
In other topics, people describes how to prevent windows shutdown. They use a dialog box for this. It helps but if the user immediately clicks in any option in this box, windows closes the application.
You can understand what I'm meaning, doing the following test:
In windows Vista or 7 Open Paint, Word or any office soft and begin writing something. Do not save it.
Try to shutdown windows and when the classic save dialog box appears IMMEDIATELY click in "cancel".
You will see that the application continues to work and windows is asking you what you want to do.
I tried to follow this Microsoft Link but if I click "ok" in Message Box, the App closes.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason.Equals(CloseReason.WindowsShutDown))
{
if (MessageBox.Show("You are closing this app.\n\nAre you sure you wish to exit ?", "Warning: Not Submitted", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop) == DialogResult.Yes)
return;
else
e.Cancel = true;
}
}
Although delay windows shutdown is not recommended it is possible using shutdown scripts. You can configure your own script file using gpedit.msc configuration file.
I have read that these scripts can delay the windows shutdown up to 10 minutes.
I hope it helps

Categories