Skip to content

Instantly share code, notes, and snippets.

@KalinovDmitri
Created March 13, 2018 11:45
Show Gist options
  • Save KalinovDmitri/f4b57c724d4ecab8787821ded14267bd to your computer and use it in GitHub Desktop.
Save KalinovDmitri/f4b57c724d4ecab8787821ded14267bd to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AsyncBrowserExample
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
SetLoadingCircleStatus(true, true);
}
protected override async void OnLoad(EventArgs e)
{
base.OnLoad(e);
await LoadDocumentAsync(new Uri("https://msdn.microsoft.com/ru-ru/"));
}
private async Task LoadDocumentAsync(Uri targetUri)
{
try
{
IAsyncResult result = BeginInvoke(new Action<Uri>(DoNavigate), targetUri);
await Task.Factory.FromAsync(result, EndInvoke);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "Exception occured.");
}
finally { }
}
private void DoNavigate(Uri targetUri)
{
Browser.Navigate(targetUri);
}
private void SetLoadingCircleStatus(bool visible, bool active)
{
LoadingCircle.Visible = visible;
LoadingCircle.Active = active;
}
private void HandleDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
SetLoadingCircleStatus(false, false);
var browser = sender as WebBrowser;
if (browser != null)
{
browser.Visible = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment